Skip to content

Commit f376341

Browse files
committed
Warn email schema console:// to be deprecated
Apps using schema console:// still works, which is converted to consolemail:// internally in order to work with django-environ. Meanwhile, a deprecation warning is output for console://. Signed-off-by: Chenxiong Qi <[email protected]>
1 parent a8c8796 commit f376341

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

configurations/values.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import decimal
44
import os
55
import sys
6+
import warnings
67

78
from django.core import validators
89
from django.core.exceptions import ValidationError, ImproperlyConfigured
@@ -414,8 +415,24 @@ def setup(self, name):
414415
return value
415416

416417

418+
def env_email_url_config(cls, url, backend=None):
419+
"""
420+
Convert schema to consolemail in order to be compatible with old
421+
console:// schema.
422+
423+
This could be removed and set EmailURLValue.caster to Env.email_url_config
424+
directly after the deprecation is removed.
425+
"""
426+
if url.startswith('console://'):
427+
warnings.warn('Email schema console:// is deprecated. Please use '
428+
'consolemail:// in new code.',
429+
DeprecationWarning)
430+
url = url.replace('console://', 'consolemail://')
431+
return Env.email_url_config(url, backend=backend)
432+
433+
417434
class EmailURLValue(CastingMixin, MultipleMixin, Value):
418-
caster = Env.email_url_config
435+
caster = env_email_url_config
419436
message = 'Cannot interpret email URL value {0!r}'
420437
late_binding = True
421438

tests/test_values.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,14 +411,18 @@ def test_email_url_value(self):
411411
'EMAIL_HOST_USER': '[email protected]',
412412
'EMAIL_PORT': 587,
413413
'EMAIL_USE_TLS': True})
414-
with env(EMAIL_URL='consolemail://'):
414+
with env(EMAIL_URL='console://'):
415415
self.assertEqual(value.setup('EMAIL_URL'), {
416416
'EMAIL_BACKEND': 'django.core.mail.backends.console.EmailBackend', # noqa: E501
417417
'EMAIL_FILE_PATH': '',
418418
'EMAIL_HOST': None,
419419
'EMAIL_HOST_PASSWORD': None,
420420
'EMAIL_HOST_USER': None,
421421
'EMAIL_PORT': None})
422+
with env(EMAIL_URL='console://'):
423+
with patch('warnings.warn') as warn:
424+
value.setup('EMAIL_URL')
425+
warn.asset_called_once()
422426
with env(EMAIL_URL='smtps://[email protected]:[email protected]:wrong'): # noqa: E501
423427
self.assertRaises(ValueError, value.setup, 'TEST')
424428

0 commit comments

Comments
 (0)