Exemplo n.º 1
0
    def test_flag_existed_and_was_active(self):
        Flag.objects.create(name='foo', everyone=True)

        with override_flag('foo', active=True):
            assert flag_is_active(req(), 'foo')

        with override_flag('foo', active=False):
            assert not flag_is_active(req(), 'foo')

        assert Flag.objects.get(name='foo').everyone
Exemplo n.º 2
0
    def test_flag_did_not_exist(self):
        assert not Flag.objects.filter(name='foo').exists()

        with override_flag('foo', active=True):
            assert flag_is_active(req(), 'foo')

        with override_flag('foo', active=False):
            assert not flag_is_active(req(), 'foo')

        assert not Flag.objects.filter(name='foo').exists()
Exemplo n.º 3
0
        def _wrapped_view(request, *args, **kwargs):
            if flag_name.startswith('!'):
                active = not flag_is_active(request, flag_name[1:])
            else:
                active = flag_is_active(request, flag_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 _generate_waffle_js(request):
    flags = cache.get(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')))
    if flags is None:
        flags = Flag.objects.values_list('name', flat=True)
        cache.add(keyfmt(get_setting('ALL_FLAGS_CACHE_KEY')), flags)
    flag_values = [(f, flag_is_active(request, f)) for f in flags]

    switches = cache.get(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')))
    if switches is None:
        switches = Switch.objects.values_list('name', 'active')
        cache.add(keyfmt(get_setting('ALL_SWITCHES_CACHE_KEY')), switches)

    samples = cache.get(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')))
    if samples is None:
        samples = Sample.objects.values_list('name', flat=True)
        cache.add(keyfmt(get_setting('ALL_SAMPLES_CACHE_KEY')), samples)
    sample_values = [(s, sample_is_active(s)) for s in samples]

    return loader.render_to_string('waffle/waffle.js', {
        'flags': flag_values,
        'switches': switches,
        'samples': sample_values,
        'flag_default': get_setting('FLAG_DEFAULT'),
        'switch_default': get_setting('SWITCH_DEFAULT'),
        'sample_default': get_setting('SAMPLE_DEFAULT'),
    })
Exemplo n.º 5
0
 def test_undecorated_method_is_set_properly_for_flag(self):
     self.assertFalse(flag_is_active(req(), 'foo'))