Example #1
0
class TestExportedSettings(TestCase):

    def setUp(self):
        self.settings = ExportedSettings(FOO='BAR')

    def test_key_access_ok(self):
        self.assertEqual(self.settings['FOO'], 'BAR')

    def test_key_access_UnexportedSettingError(self):
        with self.assertRaises(UnexportedSettingError):
            self.settings['XXX']

    def test_key_access_dict_method(self):
        """
        Since `items()` is an existing `dict` method, a KeyError needs to
        be raised instead of UnexportedSettingError, so that Django templates
        re-try with attribute access.

        Django first tries dict lookup and relies on specific exceptions being
        raised if the key is absent from the dict (specifically one of
        TypeError, AttributeError, KeyError, ValueError, IndexError).

        https://github.com/jkbrzt/django-settings-export/pull/4

        """
        with self.assertRaises(KeyError):
            self.settings['items']

    def test_key_access_dict_can_assign(self):
        """"
        When there's is a setting name colliding with a `dict` method,
        things still should work. The ability to access `items() form
        templates, is lost though, which is acceptable.

        """
        self.settings['items'] = 'value'
        self.assertEqual(self.settings['items'], 'value')

    def test_dict_keys(self):
        self.assertListEqual(list(self.settings.keys()), ['FOO'])

    def test_dict_values(self):
        self.assertListEqual(list(self.settings.values()), ['BAR'])

    def test_dict_items(self):
        self.assertListEqual(list(self.settings.items()), [('FOO', 'BAR')])
class TestExportedSettings(TestCase):
    def setUp(self):
        self.settings = ExportedSettings(FOO='BAR')

    def test_key_access_ok(self):
        self.assertEqual(self.settings['FOO'], 'BAR')

    def test_key_access_UnexportedSettingError(self):
        with self.assertRaises(UnexportedSettingError):
            self.settings['XXX']

    def test_key_access_dict_method(self):
        """
        Since `items()` is an existing `dict` method, a KeyError needs to
        be raised instead of UnexportedSettingError, so that Django templates
        re-try with attribute access.

        Django first tries dict lookup and relies on specific exceptions being
        raised if the key is absent from the dict (specifically one of
        TypeError, AttributeError, KeyError, ValueError, IndexError).

        https://github.com/jkbrzt/django-settings-export/pull/4

        """
        with self.assertRaises(KeyError):
            self.settings['items']

    def test_key_access_dict_can_assign(self):
        """"
        When there's is a setting name colliding with a `dict` method,
        things still should work. The ability to access `items() form
        templates, is lost though, which is acceptable.

        """
        self.settings['items'] = 'value'
        self.assertEqual(self.settings['items'], 'value')

    def test_dict_keys(self):
        self.assertListEqual(list(self.settings.keys()), ['FOO'])

    def test_dict_values(self):
        self.assertListEqual(list(self.settings.values()), ['BAR'])

    def test_dict_items(self):
        self.assertListEqual(list(self.settings.items()), [('FOO', 'BAR')])
Example #3
0
 def test_exported_settings_wrapper(self):
     settings = ExportedSettings({'FOO': 'BAR'})
     self.assertEqual(settings.FOO, 'BAR')
     with self.assertRaises(UnexportedSettingError):
         # noinspection PyStatementEffect
         settings.XXX
 def setUp(self):
     self.settings = ExportedSettings(FOO='BAR')
Example #5
0
 def setUp(self):
     self.settings = ExportedSettings(FOO='BAR')