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()
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
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)
def switch(parser, token): condition = lambda request, name: switch_is_active(name) return WaffleNode.handle_token(parser, token, 'switch', condition)
def test_disabled(): assert not switch_is_active('foo')
def test_enabled(): assert switch_is_active('foo')
def test_undecorated_method_is_set_properly_for_switch(self): self.assertFalse(switch_is_active('foo'))