Exemplo n.º 1
0
    def test_flag_conflicts(self):
        middleware.meets_criteria(self.request, self.criteria).AndReturn(True)
        self.flag2.conflicts.add(self.flag1)
        self.flag2.priority = 100
        self.flag2.save()
        cache.get('criteria:all')
        cache.add('criteria:all', mox.IgnoreArg())
        cache.get('criteria:test_crit:flags')
        cache.add('criteria:test_crit', mox.IgnoreArg())
        cache.add('criteria:test_crit:flags', mox.IgnoreArg())
        cache.add('criteria:test_crit:users', mox.IgnoreArg())
        cache.add('criteria:test_crit:groups', mox.IgnoreArg())
        cache.get('flag_conflicts:other_flag').InAnyOrder()
        cache.get('flag_conflicts:test_flag').InAnyOrder()
        cache.add('flag_conflicts:test_flag', mox.IgnoreArg()).InAnyOrder()
        cache.add('flag_conflicts:other_flag', mox.IgnoreArg()).InAnyOrder()

        self.mock.ReplayAll()
        self.mw.process_request(self.request)
        self.mock.VerifyAll()

        self.assertDictEqual(
            self.request.affected_persist, {})
        self.assertItemsEqual(
            self.request.affected_flags, [self.flag2.name])
Exemplo n.º 2
0
    def test_criteria_not_active(self):
        middleware.meets_criteria(self.request, self.criteria).AndReturn(False)
        cache.get('criteria:all')
        cache.add('criteria:all', mox.IgnoreArg())

        self.mock.ReplayAll()
        self.mw.process_request(self.request)
        self.mock.VerifyAll()

        self.assertDictEqual(self.request.affected_persist, {})
        self.assertListEqual(self.request.affected_flags, [])
Exemplo n.º 3
0
    def test_criteria_active_everything_cached(self):
        self.mock.StubOutWithMock(middleware, 'cache_criteria')
        cache.get('criteria:all').AndReturn(Criteria.objects.all())
        middleware.meets_criteria(self.request, self.criteria).AndReturn(True)
        cache.get('criteria:test_crit:flags').AndReturn(
            self.criteria.flags.all())
        cache.get(u'flag_conflicts:test_flag').InAnyOrder().AndReturn(
            Flag.objects.none())
        cache.get(u'flag_conflicts:other_flag').InAnyOrder().AndReturn(
            Flag.objects.none())

        self.mock.ReplayAll()
        self.mw.process_request(self.request)
        self.mock.VerifyAll()

        self.assertDictEqual(self.request.affected_persist, {})
        self.assertItemsEqual(self.request.affected_flags,
                              [self.flag1.name, self.flag2.name])
Exemplo n.º 4
0
    def test_criteria_active_nothing_cached(self):
        self.mock.StubOutWithMock(middleware, 'cache_criteria')
        cache.get('criteria:all')
        cache.add('criteria:all', mox.SameElementsAs(Criteria.objects.all()))
        middleware.meets_criteria(self.request, self.criteria).AndReturn(True)
        cache.get('criteria:test_crit:flags')
        middleware.cache_criteria(instance=self.criteria)
        cache.get(u'flag_conflicts:test_flag').InAnyOrder()
        cache.add(
            u'flag_conflicts:test_flag', mox.SameElementsAs([])).InAnyOrder()
        cache.get(u'flag_conflicts:other_flag').InAnyOrder()
        cache.add(
            u'flag_conflicts:other_flag', mox.SameElementsAs([])).InAnyOrder()

        self.mock.ReplayAll()
        self.mw.process_request(self.request)
        self.mock.VerifyAll()

        self.assertDictEqual(self.request.affected_persist, {})
        self.assertItemsEqual(self.request.affected_flags,
                              [self.flag1.name, self.flag2.name])