mirror of
https://github.com/ansible/awx.git
synced 2026-02-26 15:36:04 -03:30
add some more inline comments and minor refactoring to awx.conf
This commit is contained in:
@@ -87,6 +87,10 @@ class SettingsWrapper(UserSettingsHolder):
|
||||
``SettingsWrapper.initialize`` at app startup time when settings are
|
||||
parsed.
|
||||
"""
|
||||
|
||||
# These values have to be stored via self.__dict__ in this way to get
|
||||
# around the magic __setattr__ method on this class (which is used to
|
||||
# store API-assigned settings in the database).
|
||||
self.__dict__['default_settings'] = default_settings
|
||||
self.__dict__['_awx_conf_settings'] = self
|
||||
self.__dict__['_awx_conf_preload_expires'] = None
|
||||
|
||||
@@ -17,10 +17,19 @@ from awx.conf.registry import SettingsRegistry
|
||||
|
||||
@pytest.fixture()
|
||||
def reg(request):
|
||||
"""
|
||||
This fixture initializes an awx settings registry object and passes it as
|
||||
an argument into the test function.
|
||||
"""
|
||||
cache = LocMemCache(str(uuid4()), {}) # make a new random cache each time
|
||||
settings = LazySettings()
|
||||
registry = SettingsRegistry(settings)
|
||||
defaults = request.node.get_marker('defaults')
|
||||
|
||||
# @pytest.mark.readonly can be used to mark specific setting values as
|
||||
# "read-only". This is analogous to manually specifying a setting on the
|
||||
# filesystem (e.g., in a local_settings.py in development, or in
|
||||
# /etc/tower/conf.d/<something>.py)
|
||||
defaults = request.node.get_marker('readonly')
|
||||
if defaults:
|
||||
settings.configure(**defaults.kwargs)
|
||||
settings._wrapped = SettingsWrapper(settings._wrapped,
|
||||
@@ -271,7 +280,7 @@ def test_field_with_custom_mixin(reg):
|
||||
assert field.is_great() is True
|
||||
|
||||
|
||||
@pytest.mark.defaults(AWX_SOME_SETTING='DEFAULT')
|
||||
@pytest.mark.readonly(AWX_SOME_SETTING='DEFAULT')
|
||||
def test_default_value_from_settings(reg):
|
||||
reg.register(
|
||||
'AWX_SOME_SETTING',
|
||||
@@ -284,7 +293,7 @@ def test_default_value_from_settings(reg):
|
||||
assert field.default == 'DEFAULT'
|
||||
|
||||
|
||||
@pytest.mark.defaults(AWX_SOME_SETTING='DEFAULT')
|
||||
@pytest.mark.readonly(AWX_SOME_SETTING='DEFAULT')
|
||||
def test_default_value_from_settings_with_custom_representation(reg):
|
||||
class LowercaseCharField(fields.CharField):
|
||||
|
||||
|
||||
@@ -26,6 +26,14 @@ def apply_patches(_patches):
|
||||
|
||||
@pytest.fixture()
|
||||
def settings(request):
|
||||
"""
|
||||
This fixture initializes a Django settings object that wraps our
|
||||
`awx.conf.settings.SettingsWrapper` and passes it as an argument into the
|
||||
test function.
|
||||
|
||||
This mimics the work done by `awx.conf.settings.SettingsWrapper.initialize`
|
||||
on `django.conf.settings`.
|
||||
"""
|
||||
cache = LocMemCache(str(uuid4()), {}) # make a new random cache each time
|
||||
settings = LazySettings()
|
||||
registry = SettingsRegistry(settings)
|
||||
|
||||
Reference in New Issue
Block a user