当前位置: 首页>>代码示例>>Python>>正文


Python SwitchManager._post_save方法代码示例

本文整理汇总了Python中gargoyle.models.SwitchManager._post_save方法的典型用法代码示例。如果您正苦于以下问题:Python SwitchManager._post_save方法的具体用法?Python SwitchManager._post_save怎么用?Python SwitchManager._post_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gargoyle.models.SwitchManager的用法示例。


在下文中一共展示了SwitchManager._post_save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: APITest

# 需要导入模块: from gargoyle.models import SwitchManager [as 别名]
# 或者: from gargoyle.models.SwitchManager import _post_save [as 别名]

#.........这里部分代码省略.........
        self.assertFalse(self.gargoyle.is_active('test', self.user))

    def test_deletion(self):
        switch = Switch.objects.create(key='test')
        
        switch = self.gargoyle['test']

        self.assertTrue('test' in self.gargoyle)
        
        switch.delete()
        
        self.assertFalse('test' in self.gargoyle)

    def test_expiration(self):
        switch = Switch.objects.create(key='test')
        
        switch = self.gargoyle['test']
        
        switch.status = DISABLED
        switch.save()

        self.assertFalse(self.gargoyle.is_active('test'))

        Switch.objects.filter(key='test').update(value={}, status=GLOBAL)

        # cache shouldn't have expired
        self.assertFalse(self.gargoyle.is_active('test'))

        # in memory cache shouldnt have expired
        cache.delete(self.gargoyle.cache_key)
        self.assertFalse(self.gargoyle.is_active('test'))
        switch.status, switch.value = GLOBAL, {}
        # Ensure post save gets sent
        self.gargoyle._post_save(sender=None, instance=switch, created=False)

        # any request should expire the in memory cache
        self.client.get('/')
        
        self.assertTrue(self.gargoyle.is_active('test'))

    def test_anonymous_user(self):
        condition_set = 'gargoyle.builtins.UserConditionSet(auth.user)'

        switch = Switch.objects.create(key='test')
        
        switch = self.gargoyle['test']
        
        switch.status = SELECTIVE
        switch.save()
        
        user = AnonymousUser()

        self.assertFalse(self.gargoyle.is_active('test', user))

        switch.add_condition(
            condition_set=condition_set,
            field_name='percent',
            condition='1-10',
        )

        self.assertFalse(self.gargoyle.is_active('test', user))

        switch.clear_conditions(
            condition_set=condition_set,
        )
开发者ID:szilveszter,项目名称:gargoyle,代码行数:69,代码来源:tests.py

示例2: GargoyleTest

# 需要导入模块: from gargoyle.models import SwitchManager [as 别名]
# 或者: from gargoyle.models.SwitchManager import _post_save [as 别名]

#.........这里部分代码省略.........
        self.assertFalse(self.gargoyle.is_active("test", self.user))

    def test_deletion(self):
        switch = Switch.objects.create(key="test")

        switch = self.gargoyle["test"]

        self.assertTrue("test" in self.gargoyle)

        switch.delete()

        self.assertFalse("test" in self.gargoyle)

    def test_expiration(self):
        switch = Switch.objects.create(key="test")

        switch = self.gargoyle["test"]

        switch.status = DISABLED
        switch.save()

        self.assertFalse(self.gargoyle.is_active("test"))

        Switch.objects.filter(key="test").update(value={}, status=SELECTIVE)

        # cache shouldn't have expired
        self.assertFalse(self.gargoyle.is_active("test"))

        # in memory cache shouldnt have expired
        cache.delete(self.gargoyle.cache_key)
        self.assertFalse(self.gargoyle.is_active("test"))
        switch.status, switch.value = SELECTIVE, {}
        # Ensure post save gets sent
        self.gargoyle._post_save(sender=None, instance=switch, created=False)

        # any request should expire the in memory cache
        self.client.get("/")

        self.assertTrue(self.gargoyle.is_active("test"))

    def test_anonymous_user(self):
        condition_set = "gargoyle.builtins.UserConditionSet(auth.user)"

        switch = Switch.objects.create(key="test")

        switch = self.gargoyle["test"]

        switch.status = SELECTIVE
        switch.save()

        user = AnonymousUser()

        self.assertTrue(self.gargoyle.is_active("test", user))

        switch.add_condition(condition_set=condition_set, field_name="percent", condition="1-10")

        self.assertFalse(self.gargoyle.is_active("test", user))

        switch.clear_conditions(condition_set=condition_set)

        self.assertTrue(self.gargoyle.is_active("test", user))

        switch.add_condition(condition_set=condition_set, field_name="is_anonymous", condition="1")

        self.assertTrue(self.gargoyle.is_active("test", user))
开发者ID:slyons,项目名称:gargoyle,代码行数:69,代码来源:tests.py


注:本文中的gargoyle.models.SwitchManager._post_save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。