本文整理汇总了Python中gargoyle.manager.SwitchManager._post_save方法的典型用法代码示例。如果您正苦于以下问题:Python SwitchManager._post_save方法的具体用法?Python SwitchManager._post_save怎么用?Python SwitchManager._post_save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类gargoyle.manager.SwitchManager
的用法示例。
在下文中一共展示了SwitchManager._post_save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: APITest
# 需要导入模块: from gargoyle.manager import SwitchManager [as 别名]
# 或者: from gargoyle.manager.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.remote_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,
)
示例2: APITest
# 需要导入模块: from gargoyle.manager import SwitchManager [as 别名]
# 或者: from gargoyle.manager.SwitchManager import _post_save [as 别名]
#.........这里部分代码省略.........
def test_deletion(self):
switch = Switch.objects.create(key='test')
switch = self.gargoyle['test']
assert 'test' in self.gargoyle
switch.delete()
assert 'test' not in self.gargoyle
def test_expiration(self):
switch = Switch.objects.create(key='test')
switch = self.gargoyle['test']
switch.status = DISABLED
switch.save()
assert not self.gargoyle.is_active('test')
Switch.objects.filter(key='test').update(value={}, status=GLOBAL)
# cache shouldn't have expired
assert not self.gargoyle.is_active('test')
cache_key = self.gargoyle.remote_cache_key
# in memory cache shouldnt have expired
cache.delete(cache_key)
assert not 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('/')
assert 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()
assert not self.gargoyle.is_active('test', user)
switch.add_condition(
condition_set=condition_set,
field_name='percent',
condition='1-10',
)
assert not self.gargoyle.is_active('test', user)
switch.clear_conditions(condition_set=condition_set)
assert not self.gargoyle.is_active('test', user)