コード例 #1
0
ファイル: tests.py プロジェクト: DjangoBD/django-djconfig
 def test_config_set(self):
     """
     config set adds the item
     """
     config._set('foo', 'bar')
     self.assertTrue('foo' in config._cache)
     self.assertEqual(config.foo, 'bar')
コード例 #2
0
    def test_config_middleware_process_request(self):
        """
        config middleware, reload cache
        """
        ConfigModel.objects.create(key="char", value="foo")
        djconfig.register(BarForm)
        djconfig.reload_maybe()
        config._set('char', None)

        # Should not reload since _updated_at does not exists (form was not saved)
        middleware = DjConfigMiddleware()
        middleware.process_request(request=None)
        self.assertIsNone(config._cache.get('char'))

        # Changing _updated_at should make it reload
        ConfigModel.objects.create(key="_updated_at", value="111")
        middleware.process_request(request=None)
        self.assertEqual(config._cache.get('char'), "foo")
        self.assertEqual(config._cache.get("_updated_at"), "111")

        # It does not update again, since _updated_at has not changed
        ConfigModel.objects.filter(key="char").update(value="bar")
        middleware.process_request(request=None)
        self.assertNotEqual(config._cache.get('char'), "bar")
        self.assertEqual(config._cache.get("_updated_at"), "111")

        # Changing _updated_at should make it reload
        ConfigModel.objects.filter(key="_updated_at").update(value="222")
        middleware.process_request(request=None)
        self.assertEqual(config._cache.get('char'), "bar")
        self.assertEqual(config._cache.get("_updated_at"), "222")
コード例 #3
0
ファイル: tests.py プロジェクト: DjangoBD/django-djconfig
    def test_config_middleware_process_request(self):
        """
        config middleware, reload cache
        """
        ConfigModel.objects.create(key="char", value="foo")
        djconfig.register(BarForm)
        djconfig.reload_maybe()
        config._set('char', None)

        # Should not reload since _updated_at does not exists (form was not saved)
        middleware = DjConfigMiddleware()
        middleware.process_request(request=None)
        self.assertIsNone(config._cache.get('char'))

        # Changing _updated_at should make it reload
        ConfigModel.objects.create(key="_updated_at", value="111")
        middleware.process_request(request=None)
        self.assertEqual(config._cache.get('char'), "foo")
        self.assertEqual(config._cache.get("_updated_at"), "111")

        # It does not update again, since _updated_at has not changed
        ConfigModel.objects.filter(key="char").update(value="bar")
        middleware.process_request(request=None)
        self.assertNotEqual(config._cache.get('char'), "bar")
        self.assertEqual(config._cache.get("_updated_at"), "111")

        # Changing _updated_at should make it reload
        ConfigModel.objects.filter(key="_updated_at").update(value="222")
        middleware.process_request(request=None)
        self.assertEqual(config._cache.get('char'), "bar")
        self.assertEqual(config._cache.get("_updated_at"), "222")
コード例 #4
0
 def test_config_set(self):
     """
     config set adds the item
     """
     config._set('foo', 'bar')
     self.assertTrue('foo' in config._cache)
     self.assertEqual(config.foo, 'bar')
コード例 #5
0
ファイル: tests.py プロジェクト: krlan/gpoint
 def test_config_set(self):
     """
     config set adds the item
     """
     config._set("foo", "bar")
     self.assertTrue("foo" in config._cache)
     self.assertEqual(config.foo, "bar")
コード例 #6
0
ファイル: tests.py プロジェクト: krlan/gpoint
    def test_config_form_allow_initial_overwrite(self):
        """
        config form, allow user to pass initial data
        """
        registry.register(BarForm)
        config._set("char", "foo2")
        config._is_loaded = True

        form = BarForm(initial={"char": "bar"})
        self.assertEqual(form.initial["char"], "bar")
コード例 #7
0
ファイル: tests.py プロジェクト: DjangoBD/django-djconfig
    def test_config_form_allow_initial_overwrite(self):
        """
        config form, allow user to pass initial data
        """
        djconfig.register(BarForm)
        djconfig.reload_maybe()
        config._set("char", "foo2")

        form = BarForm(initial={'char': 'bar', 'email': '*****@*****.**'})
        self.assertEqual(form.initial['char'], 'foo2')
        self.assertEqual(form.initial['email'], '*****@*****.**')
コード例 #8
0
    def test_config_form_allow_initial_overwrite(self):
        """
        config form, allow user to pass initial data
        """
        djconfig.register(BarForm)
        djconfig.reload_maybe()
        config._set("char", "foo2")

        form = BarForm(initial={'char': 'bar', 'email': '*****@*****.**'})
        self.assertEqual(form.initial['char'], 'foo2')
        self.assertEqual(form.initial['email'], '*****@*****.**')
コード例 #9
0
    def test_config_form_allow_initial_overwrite(self):
        """
        config form, allow user to pass initial data
        """
        registry.register(BarForm)
        config._set("char", "foo2")
        config._is_loaded = True

        form = BarForm(initial={
            'char': 'bar',
        })
        self.assertEqual(form.initial['char'], 'bar')
コード例 #10
0
ファイル: tests.py プロジェクト: krlan/gpoint
    def test_config_form_populate_if_loaded(self):
        """
        config form, populate initial data only if the config is loaded
        """
        registry.register(BarForm)
        config._set("char", "foo2")

        form = BarForm()
        self.assertTrue("char" not in form.initial)

        config._is_loaded = True
        form = BarForm()
        self.assertEqual(form.initial["char"], "foo2")
コード例 #11
0
    def test_config_form_populate_if_loaded(self):
        """
        config form, populate initial data only if the config is loaded
        """
        registry.register(BarForm)
        config._set("char", "foo2")

        form = BarForm()
        self.assertTrue('char' not in form.initial)

        config._is_loaded = True
        form = BarForm()
        self.assertEqual(form.initial['char'], 'foo2')
コード例 #12
0
ファイル: tests.py プロジェクト: krlan/gpoint
    def test_config_attr_error(self):
        """
        config attribute error when it's not in keys
        """
        config = Config()

        def wrapper():
            return config.foo

        self.assertRaises(AttributeError, wrapper)

        config._set("foo", "bar")
        self.assertEqual(wrapper(), "bar")
コード例 #13
0
    def test_config_attr_error(self):
        """
        config attribute error when it's not in keys
        """
        config = Config()

        def wrapper():
            return config.foo

        self.assertRaises(AttributeError, wrapper)

        config._set('foo', 'bar')
        self.assertEqual(wrapper(), 'bar')
コード例 #14
0
ファイル: tests.py プロジェクト: DjangoBD/django-djconfig
    def test_override_djconfig(self):
        """
        Sets config variables temporarily
        """
        @override_djconfig(foo='bar', foo2='bar2')
        def my_test(my_var):
            return my_var, config.foo, config.foo2

        config._set('foo', 'org')
        config._set('foo2', 'org2')

        res = my_test("stuff")
        self.assertEqual(res, ("stuff", 'bar', 'bar2'))
        self.assertEqual((config.foo, config.foo2), ("org", 'org2'))
コード例 #15
0
    def test_override_djconfig(self):
        """
        Sets config variables temporarily
        """
        @override_djconfig(foo='bar', foo2='bar2')
        def my_test(my_var):
            return my_var, config.foo, config.foo2

        config._set('foo', 'org')
        config._set('foo2', 'org2')

        res = my_test("stuff")
        self.assertEqual(res, ("stuff", 'bar', 'bar2'))
        self.assertEqual((config.foo, config.foo2), ("org", 'org2'))
コード例 #16
0
ファイル: tests.py プロジェクト: krlan/gpoint
    def test_override_djconfig(self):
        """
        Sets config variables temporarily
        """

        @override_djconfig(foo="bar", foo2="bar2")
        def my_test(my_var):
            return my_var, config.foo, config.foo2

        config._set("foo", "org")
        config._set("foo2", "org2")

        res = my_test("stuff")
        self.assertEqual(res, ("stuff", "bar", "bar2"))
        self.assertEqual((config.foo, config.foo2), ("org", "org2"))
コード例 #17
0
ファイル: tests.py プロジェクト: DjangoBD/django-djconfig
    def test_override_djconfig_except(self):
        """
        Sets config variables temporarily, even on exceptions
        """
        @override_djconfig(foo='bar')
        def my_test():
            raise AssertionError

        config._set('foo', 'org')

        try:
            my_test()
        except AssertionError:
            pass

        self.assertEqual(config.foo, "org")
コード例 #18
0
    def test_override_djconfig_except(self):
        """
        Sets config variables temporarily, even on exceptions
        """
        @override_djconfig(foo='bar')
        def my_test():
            raise AssertionError

        config._set('foo', 'org')

        try:
            my_test()
        except AssertionError:
            pass

        self.assertEqual(config.foo, "org")