示例#1
0
    def test_local_site_feature_fallback_disabled(self):
        """Testing RBFeatureChecker.is_feature_enabled for an unconfigured
        feature on a LocalSite that is disabled globally
        """
        self.local_site.extra_data = {
            RBFeatureChecker.EXTRA_DATA_KEY: {},
        }

        with self.settings(ENABLED_FEATURES=self.FEATURE_DISABLED_SETTINGS):
            self.assertFalse(RBFeatureChecker().is_feature_enabled(
                DummyFeature.feature_id, local_site=self.local_site))
示例#2
0
    def test_local_site_feature_disabled(self):
        """Testing RBFeatureChecker.is_feature_enabled for a feature disabled
        on a local site
        """
        self.local_site.extra_data = {
            RBFeatureChecker.EXTRA_DATA_KEY: self.FEATURE_DISABLED_SETTINGS,
        }

        with self.settings(ENABLED_FEATURES=self.FEATURE_ENABLED_SETTINGS):
            self.assertTrue(RBFeatureChecker().is_feature_enabled(
                DummyFeature.feature_id, local_site=self.local_site))
示例#3
0
    def test_cache_localsite_queries(self):
        """Testing RBFeatureChecker.is_feature_enabled caches LocalSite
        membership to reduce query count
        """
        self.local_site.extra_data = {
            RBFeatureChecker.EXTRA_DATA_KEY: self.FEATURE_ENABLED_SETTINGS,
        }
        self.local_site.save()

        request = self.request_factory.get('/')
        request.user = User.objects.get(username='******')

        with self.assertNumQueries(1):
            for _ in range(3):
                self.assertTrue(RBFeatureChecker().is_feature_enabled(
                    DummyFeature.feature_id, request=request))
示例#4
0
    def test_no_queries_anonymous(self):
        """Testing RBFeatureChecker.is_feature_enabled does not query when the
        user is anonymous
        """
        self.local_site.extra_data = {
            RBFeatureChecker.EXTRA_DATA_KEY: self.FEATURE_ENABLED_SETTINGS,
        }
        self.local_site.save()

        request = self.request_factory.get('/')
        request.user = AnonymousUser()

        with self.assertNumQueries(0):
            for _ in range(3):
                self.assertFalse(RBFeatureChecker().is_feature_enabled(
                    DummyFeature.feature_id, request=request))
示例#5
0
    def test_local_site_feature_disabled_on_global(self):
        """Testing RBFeatureChecker.is_feature_enabled for a feature disabled
        on a local site while not on a site
        """
        self.local_site.extra_data = {
            RBFeatureChecker.EXTRA_DATA_KEY: self.FEATURE_DISABLED_SETTINGS,
        }
        self.local_site.save()

        request = self.request_factory.get('/')
        request.user = User.objects.get(username='******')
        request.local_site = None

        with self.settings(ENABLED_FEATURES=self.FEATURE_ENABLED_SETTINGS):
            self.assertTrue(RBFeatureChecker().is_feature_enabled(
                DummyFeature.feature_id, request=request))