mirror of
https://github.com/jazzband/django-configurations.git
synced 2026-03-16 22:20:27 +00:00
Merge fb7417fa76 into 141d8ef2c4
This commit is contained in:
commit
e65091f7eb
3 changed files with 31 additions and 22 deletions
|
|
@ -3,9 +3,11 @@ import copy
|
|||
import decimal
|
||||
import os
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
from django.core import validators
|
||||
from django.core.exceptions import ValidationError, ImproperlyConfigured
|
||||
from environ import Env
|
||||
from django.utils.module_loading import import_string
|
||||
|
||||
from .utils import getargspec
|
||||
|
|
@ -418,8 +420,24 @@ class SecretValue(Value):
|
|||
return value
|
||||
|
||||
|
||||
def env_email_url_config(cls, url, backend=None):
|
||||
"""
|
||||
Convert schema to consolemail in order to be compatible with old
|
||||
console:// schema.
|
||||
|
||||
This could be removed and set EmailURLValue.caster to Env.email_url_config
|
||||
directly after the deprecation is removed.
|
||||
"""
|
||||
if url.startswith('console://'):
|
||||
warnings.warn('Email schema console:// is deprecated. Please use '
|
||||
'consolemail:// in new code.',
|
||||
DeprecationWarning)
|
||||
url = url.replace('console://', 'consolemail://')
|
||||
return Env.email_url_config(url, backend=backend)
|
||||
|
||||
|
||||
class EmailURLValue(CastingMixin, MultipleMixin, Value):
|
||||
caster = 'dj_email_url.parse'
|
||||
caster = env_email_url_config
|
||||
message = 'Cannot interpret email URL value {0!r}'
|
||||
late_binding = True
|
||||
|
||||
|
|
@ -454,21 +472,21 @@ class DictBackendMixin(Value):
|
|||
|
||||
|
||||
class DatabaseURLValue(DictBackendMixin, CastingMixin, Value):
|
||||
caster = 'dj_database_url.parse'
|
||||
caster = Env.db_url_config
|
||||
message = 'Cannot interpret database URL value {0!r}'
|
||||
environ_name = 'DATABASE_URL'
|
||||
late_binding = True
|
||||
|
||||
|
||||
class CacheURLValue(DictBackendMixin, CastingMixin, Value):
|
||||
caster = 'django_cache_url.parse'
|
||||
caster = Env.cache_url_config
|
||||
message = 'Cannot interpret cache URL value {0!r}'
|
||||
environ_name = 'CACHE_URL'
|
||||
late_binding = True
|
||||
|
||||
|
||||
class SearchURLValue(DictBackendMixin, CastingMixin, Value):
|
||||
caster = 'dj_search_url.parse'
|
||||
caster = Env.search_url_config
|
||||
message = 'Cannot interpret Search URL value {0!r}'
|
||||
environ_name = 'SEARCH_URL'
|
||||
late_binding = True
|
||||
|
|
|
|||
6
setup.py
6
setup.py
|
|
@ -26,16 +26,14 @@ setup(
|
|||
'django-cadmin = configurations.management:execute_from_command_line',
|
||||
],
|
||||
},
|
||||
|
||||
install_requires=[
|
||||
'django>=2.2',
|
||||
'django-environ',
|
||||
'importlib-metadata;python_version<"3.8"',
|
||||
],
|
||||
python_requires='>=3.6, <4.0',
|
||||
extras_require={
|
||||
'cache': ['django-cache-url'],
|
||||
'database': ['dj-database-url'],
|
||||
'email': ['dj-email-url'],
|
||||
'search': ['dj-search-url'],
|
||||
'testing': [
|
||||
'django-cache-url>=1.0.0',
|
||||
'dj-database-url',
|
||||
|
|
|
|||
|
|
@ -374,7 +374,6 @@ class ValueTests(TestCase):
|
|||
with env(DATABASE_URL='sqlite://'):
|
||||
self.assertEqual(value.setup('DATABASE_URL'), {
|
||||
'default': {
|
||||
'CONN_MAX_AGE': 0,
|
||||
'ENGINE': 'django.db.backends.sqlite3',
|
||||
'HOST': '',
|
||||
'NAME': ':memory:',
|
||||
|
|
@ -411,7 +410,6 @@ class ValueTests(TestCase):
|
|||
'EMAIL_HOST_PASSWORD': 'password',
|
||||
'EMAIL_HOST_USER': 'user@domain.com',
|
||||
'EMAIL_PORT': 587,
|
||||
'EMAIL_USE_SSL': False,
|
||||
'EMAIL_USE_TLS': True})
|
||||
with env(EMAIL_URL='console://'):
|
||||
self.assertEqual(value.setup('EMAIL_URL'), {
|
||||
|
|
@ -420,9 +418,11 @@ class ValueTests(TestCase):
|
|||
'EMAIL_HOST': None,
|
||||
'EMAIL_HOST_PASSWORD': None,
|
||||
'EMAIL_HOST_USER': None,
|
||||
'EMAIL_PORT': None,
|
||||
'EMAIL_USE_SSL': False,
|
||||
'EMAIL_USE_TLS': False})
|
||||
'EMAIL_PORT': None})
|
||||
with env(EMAIL_URL='console://'):
|
||||
with patch('warnings.warn') as warn:
|
||||
value.setup('EMAIL_URL')
|
||||
warn.asset_called_once()
|
||||
with env(EMAIL_URL='smtps://user@domain.com:password@smtp.example.com:wrong'): # noqa: E501
|
||||
self.assertRaises(ValueError, value.setup, 'TEST')
|
||||
|
||||
|
|
@ -430,7 +430,7 @@ class ValueTests(TestCase):
|
|||
cache_setting = {
|
||||
'default': {
|
||||
'BACKEND': 'django_redis.cache.RedisCache',
|
||||
'LOCATION': 'redis://host:6379/1',
|
||||
'LOCATION': 'redis://user@host:6379/1',
|
||||
}
|
||||
}
|
||||
cache_url = 'redis://user@host:6379/1'
|
||||
|
|
@ -443,13 +443,7 @@ class ValueTests(TestCase):
|
|||
with env(CACHE_URL='wrong://user@host:port/1'):
|
||||
with self.assertRaises(Exception) as cm:
|
||||
value.setup('TEST')
|
||||
self.assertEqual(cm.exception.args[0], 'Unknown backend: "wrong"')
|
||||
with env(CACHE_URL='redis://user@host:port/1'):
|
||||
with self.assertRaises(ValueError) as cm:
|
||||
value.setup('TEST')
|
||||
self.assertEqual(
|
||||
cm.exception.args[0],
|
||||
"Cannot interpret cache URL value 'redis://user@host:port/1'")
|
||||
self.assertEqual(cm.exception.args[0], 'wrong')
|
||||
|
||||
def test_search_url_value(self):
|
||||
value = SearchURLValue()
|
||||
|
|
@ -503,7 +497,6 @@ class ValueTests(TestCase):
|
|||
'EMAIL_HOST_PASSWORD': 'password',
|
||||
'EMAIL_HOST_USER': 'user@domain.com',
|
||||
'EMAIL_PORT': 587,
|
||||
'EMAIL_USE_SSL': False,
|
||||
'EMAIL_USE_TLS': True
|
||||
})
|
||||
self.assertEqual(
|
||||
|
|
|
|||
Loading…
Reference in a new issue