def test_is_active_function_is_cached(self): self.tenant_switch.countries.add(connection.tenant) self.tenant_switch.save() # <- save is necessary to mimic the admin with self.assertNumQueries(2): # First time takes 2 queries (one to get switch, and one to get countries list) switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertTrue(switch_active) with self.assertNumQueries(0): # Second time, takes zero queries switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertTrue(switch_active)
def test_is_active_function_is_cached(self): self.tenant_switch.countries.add(connection.tenant) self.tenant_switch.save() # <- save is necessary to mimic the admin with self.assertNumQueries(2): # First time takes 2 queries (one to get switch, and one to get countries list) switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertTrue(switch_active) with self.assertNumQueries(0): # Second time, takes zero queries switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertTrue(switch_active)
def test_is_active_function_switch_on(self): self.tenant_switch.countries.add(connection.tenant) # In tests, we have to manually flush the cache. When created through # the admin, the only way to change countries is to click the 'Save' # button, which flushes the cache self.tenant_switch.save() # <- save is necessary to mimic the admin switch_active = tenant_switch_is_active(self.tenant_switch.name) # tenant in countries, so this should return True self.assertTrue(switch_active)
def test_is_active_function_switch_on(self): self.tenant_switch.countries.add(connection.tenant) # In tests, we have to manually flush the cache. When created through # the admin, the only way to change countries is to click the 'Save' # button, which flushes the cache self.tenant_switch.save() # <- save is necessary to mimic the admin switch_active = tenant_switch_is_active(self.tenant_switch.name) # tenant in countries, so this should return True self.assertTrue(switch_active)
def list(self, request, *args, **kwargs): """ Override list() to check each flag against this request and return just a list of active flags. """ flag_serializer = TenantFlagSerializer(TenantFlag.objects, many=True) switch_serializer = TenantSwitchSerializer(TenantSwitch.objects, many=True) # use set comprehensions so we never get dupes in this list active_flags = { flag['name'] for flag in flag_serializer.data if tenant_flag_is_active(request, flag['name']) } active_flags.update([ switch['name'] for switch in switch_serializer.data if tenant_switch_is_active(switch['name']) ]) return Response({'active_flags': list(active_flags)})
def list(self, request, *args, **kwargs): """ Override list() to check each flag against this request and return just a list of active flags. """ flag_serializer = TenantFlagSerializer(TenantFlag.objects, many=True) switch_serializer = TenantSwitchSerializer(TenantSwitch.objects, many=True) # use set comprehensions so we never get dupes in this list active_flags = { flag['name'] for flag in flag_serializer.data if tenant_flag_is_active(request, flag['name']) } active_flags.update([ switch['name'] for switch in switch_serializer.data if tenant_switch_is_active(switch['name']) ]) return Response({'active_flags': list(active_flags)})
def prp_server_on(): return tenant_switch_is_active("prp_server_on")
def prp_mode_off(): return tenant_switch_is_active("prp_mode_off")
def test_is_active_function_nonexistent_switch(self): "Nonexistent TenantSwitch should return False." switch_active = tenant_switch_is_active('foo') self.assertFalse(switch_active)
def test_is_active_function_switch_off(self): "Return False if tenant not in countries" switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertFalse(switch_active)
def prp_server_on(): return tenant_switch_is_active("prp_server_on")
def prp_mode_off(): return tenant_switch_is_active("prp_mode_off")
def test_is_active_function_nonexistent_switch(self): "Nonexistent TenantSwitch should return False." switch_active = tenant_switch_is_active('foo') self.assertFalse(switch_active)
def test_is_active_function_switch_off(self): "Return False if tenant not in countries" switch_active = tenant_switch_is_active(self.tenant_switch.name) self.assertFalse(switch_active)