def test_value(self): id_object = object() with patch('django_pluggableappsettings.Setting._get_value', MagicMock(return_value=id_object)) as _get_value: setting = Setting('default') self.assertEqual(setting.value(), id_object) _get_value.assert_called_with()
def test_get(self): with patch('django_pluggableappsettings.Setting._get', MagicMock(return_value=42)) as _get: setting = Setting('default') setting.get('SETTING', 'settings_value') self.assertEqual(setting._value, 42) _get.assert_called_with('SETTING', 'settings_value')
def test__get_value(self): setting = Setting('default') #raises error without a value set self.assertRaises(RuntimeError, setting._get_value) #returns value if it is set id_object = object() setting._value = id_object self.assertEqual(setting._get_value(), id_object)
class SharkSettings(AppSettings): SHARK_PAGE_HANDLER = StringSetting('') SHARK_USE_STATIC_PAGES = Setting(True) SHARK_GOOGLE_ANALYTICS_CODE = StringSetting('') CLOUDFLARE_CLIENT_IP_ENABLED = Setting(False) PROXY_HOPS = IntSetting(2) SHARK_GOOGLE_VERIFICATION = StringSetting('') SHARK_BING_VERIFICATION = StringSetting('') SHARK_YANDEX_VERIFICATION = StringSetting('') SHARK_GOOGLE_BROWSER_API_KEY = StringSetting('') SHARK_FACEBOOK_APP_ID = StringSetting('') SHARK_FACEBOOK_SECRET = StringSetting('')
def test___init__(self): setting = Setting('default') self.assertEqual(setting.default_value, 'default') setting = Setting(default_value='default') self.assertEqual(setting.default_value, 'default') # test setting of settings_name setting = Setting(settings_name='SOME_NAME') self.assertEqual(setting._settings_name, 'SOME_NAME') # test alias_possibilities setting = Setting(aliases='abc') self.assertEqual(setting._aliases, ['a', 'b', 'c']) setting = Setting(aliases=('abc', 1, 3)) self.assertEqual(setting._aliases, ['abc']) setting = Setting(aliases=1) self.assertEqual(setting._aliases, [])
class TestAppSettings(AppSettings): SETTING = Setting('Value')
class TestAppSettings(AppSettings): SETTING = Setting('Default', aliases=['ALIAS', 'ALIAS2'])
def test__get_settings_value(self): setting = Setting('default') val = setting._get('SETTING', 'settings_value') self.assertEqual(val, 'settings_value')
def test__get_default(self): setting = Setting('default') val = setting._get('SETTING', NOT_SET_VALUE) self.assertEqual(val, 'default')
def test__get_no_setting_no_default(self): setting = Setting() self.assertRaisesMessage( AttributeError, "The setting SETTING is not defined in your settings.py and no default value is provided.", setting._get, 'SETTING', NOT_SET_VALUE)
def test_get_aliases(self): id_obj = object() setting = Setting() setting._aliases = id_obj self.assertEqual(setting.get_aliases(), id_obj)
def test_get_settings_name(self): setting = Setting(settings_name='SOME_NAME') self.assertEqual(setting.get_settings_name(), 'SOME_NAME')
class Settings2(AppSettings): TEST = Setting(id_obj2) TEST2 = Setting(id_obj2)
class Settings1(AppSettings): TEST = Setting(id_obj1) TEST1 = Setting(id_obj1)
class TestSettings(AppSettings): SETTING = Setting(settings_name='OTHER_NAME')
def setUp(self): self.values = {} TestAppSettings._values = self.values settings.EXISTENT = 'valid_setting' settings.EXISTENT_APP_SETTING = Setting('valid_setting')