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


Python SwitchManager.unregister方法代码示例

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


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

示例1: APITest

# 需要导入模块: from gargoyle.manager import SwitchManager [as 别名]
# 或者: from gargoyle.manager.SwitchManager import unregister [as 别名]
class APITest(TestCase):

    request_factory = RequestFactory()

    def setUp(self):
        self.user = User.objects.create(username='foo', email='[email protected]')
        self.gargoyle = SwitchManager(Switch, key='key', value='value', instances=True, auto_create=True)
        self.gargoyle.register(UserConditionSet(User))
        self.gargoyle.register(IPAddressConditionSet())

    def test_register_unregister_class(self):
        klass = IPAddressConditionSet
        registered = self.gargoyle.register(IPAddressConditionSet)
        assert registered is klass

        unregistered = self.gargoyle.unregister(klass)
        assert unregistered

        unregistered = self.gargoyle.unregister(klass)
        assert not unregistered

    def test_register_unregister_instance(self):
        condition_set = IPAddressConditionSet()
        registered = self.gargoyle.register(condition_set)
        assert registered is condition_set

        unregistered = self.gargoyle.unregister(condition_set)
        assert unregistered

        unregistered = self.gargoyle.unregister(condition_set)
        assert not unregistered

    def test_builtin_registration(self):
        assert 'gargoyle.builtins.UserConditionSet(auth.user)' in self.gargoyle._registry
        assert 'gargoyle.builtins.IPAddressConditionSet' in self.gargoyle._registry
        assert len(list(self.gargoyle.get_condition_sets())) == 2

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

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

        switch.add_condition(
            condition_set=condition_set,
            field_name='percent',
            condition='0-50',
        )

        user = User(pk=5)
        assert self.gargoyle.is_active('test', user)

        user = User(pk=8771)
        assert not self.gargoyle.is_active('test', user)

        switch.add_condition(
            condition_set=condition_set,
            field_name='is_staff',
            condition='1',
        )

        user = User(pk=8771, is_staff=True)
        assert self.gargoyle.is_active('test', user)

        user = User(pk=8771, is_superuser=True)
        assert not self.gargoyle.is_active('test', user)

        switch.add_condition(
            condition_set=condition_set,
            field_name='is_superuser',
            condition='1',
        )

        user = User(pk=8771, is_superuser=True)
        assert self.gargoyle.is_active('test', user)

        # test with request
        request = self.request_factory.get('/', user=user)
        assert self.gargoyle.is_active('test', request)

        # test date joined condition
        user = User(pk=8771)
        assert not self.gargoyle.is_active('test', user)

        switch.add_condition(
            condition_set=condition_set,
            field_name='date_joined',
            condition='2011-07-01',
        )

        user = User(pk=8771, date_joined=datetime.datetime(2011, 7, 2))
        assert self.gargoyle.is_active('test', user)

        user = User(pk=8771, date_joined=datetime.datetime(2012, 7, 2))
        assert self.gargoyle.is_active('test', user)

        user = User(pk=8771, date_joined=datetime.datetime(2011, 6, 2))
        assert not self.gargoyle.is_active('test', user)

        user = User(pk=8771, date_joined=datetime.datetime(2011, 7, 1))
#.........这里部分代码省略.........
开发者ID:pombredanne,项目名称:gargoyle,代码行数:103,代码来源:test_api.py


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