示例#1
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')
示例#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
    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
    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
    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
    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")