Exemplo n.º 1
0
    def test_new_switch(self):
        assert not Switch.objects.filter(name='foo').exists()

        with override_switch('foo', active=True):
            assert switch_is_active('foo')

        with override_switch('foo', active=False):
            assert not switch_is_active('foo')

        assert not Switch.objects.filter(name='foo').exists()
Exemplo n.º 2
0
    def test_switch_existed_and_was_NOT_active(self):
        Switch.objects.create(name='foo', active=False)

        with override_switch('foo', active=True):
            assert switch_is_active('foo')

        with override_switch('foo', active=False):
            assert not switch_is_active('foo')

        # make sure it didn't change 'active' value
        assert not Switch.objects.get(name='foo').active
Exemplo n.º 3
0
        def _wrapped_view(request, *args, **kwargs):
            if switch_name.startswith('!'):
                active = not switch_is_active(switch_name[1:])
            else:
                active = switch_is_active(switch_name)

            if not active:
                response_to_redirect_to = get_response_to_redirect(redirect_to)
                if response_to_redirect_to:
                    return response_to_redirect_to
                else:
                    raise Http404

            return view(request, *args, **kwargs)
Exemplo n.º 4
0
def switch(parser, token):
    condition = lambda request, name: switch_is_active(name)
    return WaffleNode.handle_token(parser, token, 'switch', condition)
Exemplo n.º 5
0
 def test_disabled():
     assert not switch_is_active('foo')
Exemplo n.º 6
0
 def test_enabled():
     assert switch_is_active('foo')
Exemplo n.º 7
0
 def test_undecorated_method_is_set_properly_for_switch(self):
     self.assertFalse(switch_is_active('foo'))