Пример #1
0
    def test_recording(self):
        self.assertEqual(len(self.panel.checks), 0)

        self.panel.enable_instrumentation()
        flag_state("MYFLAG")
        self.panel.disable_instrumentation()

        self.assertEqual(len(self.panel.checks), 1)

        response = self.panel.process_request(self.request)
        self.panel.generate_stats(self.request, response)
        checks = self.panel.get_stats()["checks"]

        self.assertIn("MYFLAG", checks)
        self.assertEqual([True], checks["MYFLAG"])
Пример #2
0
    def detail_view(self, request, pk):

        any_hidden = False

        response = super().detail_view(request, pk)
        page = Page.objects.get(pk=pk)

        # Implementing User Authentication
        auth_user = json.loads(get_user_data(request).content.decode())

        # Fetching User Information and Overwriting auth_user
        if "user" in auth_user:
            auth_user = get_user_info(auth_user["user"]["id"])

        # Overwriting the Response if ox credential does not
        # authorize faculty access.
        if "faculty_status" not in auth_user or auth_user[
                "faculty_status"] != "confirmed_faculty":
            if flag_state('hide_faculty_resources', bool=True):
                any_hidden = remove_locked_links_detail(response)

        # Implementing Caching
        response['Cache-Control'] = 'no-cache'

        # If we ended up revealing a link, then force the content to be loaded.
        if not any_hidden or request.GET.get('force-reload'):
            response['Last-Modified'] = timezone.now()

        return response
Пример #3
0
        def inner(request, *args, **kwargs):
            enabled = flag_state(flag_name, request=request, **fc_kwargs)

            if (state and enabled) or (not state and not enabled):
                return func(request, *args, **kwargs)
            elif fallback is not None:
                return fallback(request, *args, **kwargs)
            else:
                raise Http404
Пример #4
0
    def listing_view(self, request):

        response = super().listing_view(request)

        # Implementing User Authentication
        auth_user = json.loads(get_user_data(request).content.decode())

        # Fetching User Information and Overwriting auth_user
        if "user" in auth_user:
            auth_user = get_user_info(auth_user["user"]["id"])

        # Overwriting the Response if ox credential does not
        # authorize faculty access.
        if "faculty_status" not in auth_user or auth_user[
                "faculty_status"] != "confirmed_faculty":
            if flag_state('hide_faculty_resources', bool=True):
                remove_locked_links_listing(response)

        return response
Пример #5
0
 def test_flag_state_apps_not_ready(self, mock_apps):
     mock_apps.ready = False
     with self.assertRaises(AppRegistryNotReady):
         self.assertTrue(flag_state("FLAG_ENABLED"))
Пример #6
0
 def test_flag_state_non_existent_flag_site(self):
     """Given a site non-existent flags should still be False"""
     request = self.factory.get("/test")
     self.assertFalse(flag_state("FLAG_DOES_NOT_EXIST", request=request))
Пример #7
0
 def test_flag_state_disabled(self):
     """Global flags that are disabled should be False"""
     self.assertFalse(flag_state("FLAG_DISABLED"))
Пример #8
0
 def test_flag_state_enabled(self):
     """Global flags that are enabled should be True"""
     self.assertTrue(flag_state("FLAG_ENABLED"))
Пример #9
0
 def test_non_existent_flag_evaluates_to_false(self):
     """Non-existent flags are falsy"""
     self.assertFalse(flag_state("FLAG_DOES_NOT_EXIST"))
Пример #10
0
 def test_non_existent_flag(self):
     """Non-existent flags return None"""
     self.assertIsNone(flag_state("FLAG_DOES_NOT_EXIST"))
Пример #11
0
 def test_flag_state_without_middleware_has_no_cached_request_flags(self):
     request = self.factory.get('/test')
     with override_settings(FLAGS={}):
         self.assertFalse(flag_state('FLAG_ENABLED', request=request))
Пример #12
0
 def test_flag_state_uses_cached_request_flags(self):
     request = self.factory.get('/test')
     self.middleware.process_request(request)
     with override_settings(FLAGS={}):
         self.assertTrue(flag_state('FLAG_ENABLED', request=request))
Пример #13
0
 def test_flag_state_non_existent_flag_site(self):
     """ Given a site non-existent flags should still be False """
     self.assertFalse(
         flag_state('FLAG_DOES_NOT_EXIST', request=self.request))
Пример #14
0
 def test_non_existent_flag(self):
     """ Non-existent flags always have a default state of False """
     self.assertFalse(flag_state('FLAG_DOES_NOT_EXIST'))