diff --git a/awx/conf/settings.py b/awx/conf/settings.py index 076340afa9..fefca9d94a 100644 --- a/awx/conf/settings.py +++ b/awx/conf/settings.py @@ -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 diff --git a/awx/conf/tests/unit/test_registry.py b/awx/conf/tests/unit/test_registry.py index 1516c72605..95db1c3c73 100644 --- a/awx/conf/tests/unit/test_registry.py +++ b/awx/conf/tests/unit/test_registry.py @@ -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/.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): diff --git a/awx/conf/tests/unit/test_settings.py b/awx/conf/tests/unit/test_settings.py index feb42df803..08bc1eafff 100644 --- a/awx/conf/tests/unit/test_settings.py +++ b/awx/conf/tests/unit/test_settings.py @@ -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)