mirror of
https://github.com/jazzband/django-configurations.git
synced 2026-03-16 22:20:27 +00:00
Place global "use_pathlib" option directly on "PathValue"
Also, add an associated test.
This commit is contained in:
parent
10914f9605
commit
8c14c12df8
2 changed files with 15 additions and 3 deletions
|
|
@ -29,7 +29,6 @@ class Value:
|
|||
multiple = False
|
||||
late_binding = False
|
||||
environ_required = False
|
||||
use_pathlib = False
|
||||
|
||||
@property
|
||||
def value(self):
|
||||
|
|
@ -391,9 +390,11 @@ class RegexValue(ValidationMixin, Value):
|
|||
|
||||
|
||||
class PathValue(Value):
|
||||
use_pathlib = False
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.check_exists = kwargs.pop('check_exists', True)
|
||||
self.use_pathlib = kwargs.pop('use_pathlib', self.use_pathlib)
|
||||
self.use_pathlib = kwargs.pop('use_pathlib', PathValue.use_pathlib)
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
def setup(self, name):
|
||||
|
|
|
|||
|
|
@ -354,7 +354,7 @@ class ValueTests(TestCase):
|
|||
with env(DJANGO_TEST='/does/not/exist'):
|
||||
self.assertEqual(value.setup('TEST'), '/does/not/exist')
|
||||
|
||||
def test_path_values_with_pathlib(self):
|
||||
def test_path_values_use_pathlib(self):
|
||||
value = PathValue(use_pathlib=True)
|
||||
with env(DJANGO_TEST='/'):
|
||||
self.assertEqual(value.setup('TEST'), Path('/'))
|
||||
|
|
@ -363,6 +363,17 @@ class ValueTests(TestCase):
|
|||
with env(DJANGO_TEST='/does/not/exist'):
|
||||
self.assertRaises(ValueError, value.setup, 'TEST')
|
||||
|
||||
def test_path_values_use_pathlib_global(self):
|
||||
PathValue.use_pathlib = True
|
||||
try:
|
||||
value = PathValue()
|
||||
self.assertTrue(value.use_pathlib)
|
||||
with env(DJANGO_TEST='/'):
|
||||
self.assertEqual(value.setup('TEST'), Path('/'))
|
||||
finally:
|
||||
# Reset global state
|
||||
PathValue.use_pathlib = False
|
||||
|
||||
def test_secret_value(self):
|
||||
# no default allowed, only environment values are
|
||||
self.assertRaises(ValueError, SecretValue, 'default')
|
||||
|
|
|
|||
Loading…
Reference in a new issue