Esempio n. 1
0
 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)
Esempio n. 2
0
 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))
Esempio n. 3
0
 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))
Esempio n. 4
0
 def test_list_flags_only(self):
     everyone_flag = TenantFlagFactory(everyone=True)
     nobody_flag = TenantFlagFactory(everyone=False)
     rsp = self.forced_auth_req('get', self.url)
     self.assertEqual(rsp.status_code, status.HTTP_200_OK)
     active_flags = json.loads(rsp.content)['active_flags']
     self.assertIn(everyone_flag.name, active_flags)
     self.assertNotIn(nobody_flag.name, active_flags)
Esempio n. 5
0
 def test_flag_and_switch_have_same_name(self):
     country = CountryFactory()
     connection.tenant = country
     same_name = 'identical'
     TenantSwitchFactory(countries=[country], name=same_name)
     TenantFlagFactory(everyone=True, name=same_name)
     rsp = self.forced_auth_req('get', self.url)
     self.assertEqual(rsp.status_code, status.HTTP_200_OK)
     active_flags = json.loads(rsp.content)['active_flags']
     self.assertEqual(len(active_flags), 1)
     self.assertIn(same_name, active_flags)
Esempio n. 6
0
 def test_returns_both_flags_and_switches(self):
     country = CountryFactory()
     connection.tenant = country
     tenant_switch = TenantSwitchFactory(countries=[country])
     nontenant_switch = TenantSwitchFactory(countries=[])
     everyone_flag = TenantFlagFactory(everyone=True)
     rsp = self.forced_auth_req('get', self.url)
     self.assertEqual(rsp.status_code, status.HTTP_200_OK)
     active_flags = json.loads(rsp.content)['active_flags']
     self.assertIn(everyone_flag.name, active_flags)
     self.assertIn(tenant_switch.name, active_flags)
     self.assertNotIn(nontenant_switch.name, active_flags)
Esempio n. 7
0
 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))
Esempio n. 8
0
 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))
Esempio n. 9
0
 def setUpTestData(cls):
     cls.tenant_flag = TenantFlagFactory(superusers=False)
     cls.country = CountryFactory()
     cls.user = UserFactory()
Esempio n. 10
0
 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))
Esempio n. 11
0
 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))
Esempio n. 12
0
 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))
Esempio n. 13
0
 def test_authenticated_flag(self):
     f = TenantFlagFactory(authenticated=True)
     self.assertTrue(f.is_active(self.request))
Esempio n. 14
0
 def test_staff_flag(self):
     f = TenantFlagFactory(staff=True)
     self.request.user.is_staff = True
     self.assertTrue(f.is_active(self.request))
Esempio n. 15
0
 def test_override_not_this_flag(self):
     f = TenantFlagFactory()
     self.request.GET = {}
     self.assertFalse(f.is_active(self.request))
Esempio n. 16
0
 def test_override(self):
     f = TenantFlagFactory()
     self.request.GET = {f.name: '1'}
     self.assertTrue(f.is_active(self.request))
Esempio n. 17
0
 def test_languages_flag_false(self):
     f = TenantFlagFactory(languages='foo,bar')
     self.request.LANGUAGE_CODE = 'nope'
     self.assertFalse(f.is_active(self.request))
Esempio n. 18
0
 def test_superuser_flag(self):
     f = TenantFlagFactory(superusers=True)
     self.request.user.is_superuser = True
     self.assertTrue(f.is_active(self.request))