예제 #1
0
 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)
예제 #2
0
 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)
예제 #3
0
 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)
예제 #4
0
 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)
예제 #5
0
파일: views.py 프로젝트: unicef/etools
    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)})
예제 #6
0
    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)})
예제 #7
0
 def prp_server_on():
     return tenant_switch_is_active("prp_server_on")
예제 #8
0
 def prp_mode_off():
     return tenant_switch_is_active("prp_mode_off")
예제 #9
0
 def test_is_active_function_nonexistent_switch(self):
     "Nonexistent TenantSwitch should return False."
     switch_active = tenant_switch_is_active('foo')
     self.assertFalse(switch_active)
예제 #10
0
 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)
예제 #11
0
 def prp_server_on():
     return tenant_switch_is_active("prp_server_on")
예제 #12
0
 def prp_mode_off():
     return tenant_switch_is_active("prp_mode_off")
예제 #13
0
 def test_is_active_function_nonexistent_switch(self):
     "Nonexistent TenantSwitch should return False."
     switch_active = tenant_switch_is_active('foo')
     self.assertFalse(switch_active)
예제 #14
0
 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)