def test_empty_user_set_is_cached(self): f = TenantFlagFactory() with self.assertNumQueries(4): self.assertFalse(f.is_active(self.request)) with self.assertNumQueries(1): # we still need to query the user's list of groups self.assertFalse(f.is_active(self.request))
def test_user_set_is_cached(self): f = TenantFlagFactory() f.users.add(self.user) f.save() with self.assertNumQueries(2): self.assertTrue(f.is_active(self.request)) with self.assertNumQueries(0): self.assertTrue(f.is_active(self.request))
def test_group_set_is_cached(self): f = TenantFlagFactory() group = GroupFactory() f.groups.add(group) f.save() self.user.groups.add(group) with self.assertNumQueries(4): self.assertTrue(f.is_active(self.request)) with self.assertNumQueries(1): # we still need to query the user's list of groups self.assertTrue(f.is_active(self.request))
def test_percent_high(self): f = TenantFlagFactory(percent=99.9) self.request.waffles = {} self.request.COOKIES = {} # random, so we don't really care about the result, just that this path # gets covered on most runs self.assertFalse(f.is_active(self.request) is None)
def test_testing_mode_request(self): f = TenantFlagFactory(testing=True) cookie_name = 'foo_%s' % f.name self.request.GET = {cookie_name: None} self.request.waffle_tests = {f.name: None} self.request.COOKIES = {cookie_name: None} self.assertFalse(f.is_active(self.request))
def test_percent_uses_cookie_preferentially(self): f = TenantFlagFactory(percent=0.1) cookie_name = 'foo_%s' % f.name self.request.waffles = {} self.request.COOKIES = {cookie_name: 'True'} self.assertTrue(f.is_active(self.request))
def test_percent_uses_waffles_preferentially(self): f = TenantFlagFactory(percent=0.1) self.request.waffles = {f.name: [True]} self.request.COOKIES = {} self.assertTrue(f.is_active(self.request))
def test_testing_mode_no_request_or_cookie(self): f = TenantFlagFactory(testing=True) self.request.GET = {} self.request.COOKIES = {} self.assertFalse(f.is_active(self.request))
def test_override_not_this_flag(self): f = TenantFlagFactory() self.request.GET = {} self.assertFalse(f.is_active(self.request))
def test_override(self): f = TenantFlagFactory() self.request.GET = {f.name: '1'} self.assertTrue(f.is_active(self.request))
def test_languages_flag_false(self): f = TenantFlagFactory(languages='foo,bar') self.request.LANGUAGE_CODE = 'nope' self.assertFalse(f.is_active(self.request))
def test_superuser_flag(self): f = TenantFlagFactory(superusers=True) self.request.user.is_superuser = True self.assertTrue(f.is_active(self.request))
def test_staff_flag(self): f = TenantFlagFactory(staff=True) self.request.user.is_staff = True self.assertTrue(f.is_active(self.request))
def test_authenticated_flag(self): f = TenantFlagFactory(authenticated=True) self.assertTrue(f.is_active(self.request))