def test_does_nothing_without_dev_param(self): request = RequestFactory().get('/?pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, None) request = RequestFactory().get('/?device=mobilepro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, None)
def test_does_nothing_without_dev_param(self): request = RequestFactory().get('/?pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, None) request = RequestFactory().get( '/?device=mobilepro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, None)
def get_feature_compatibility(self, app): request = self.context['request'] if not hasattr(request, 'feature_profile'): load_feature_profile(request) if request.feature_profile is None: # No profile information sent, we can't return compatibility, # return null. return None app_features = app.current_version.features.to_list() return request.feature_profile.has_features(app_features)
def get_feature_compatibility(self, app): request = self.context['request'] if not hasattr(request, 'feature_profile'): load_feature_profile(request) if request.feature_profile is None or app.current_version is None: # No profile information sent, or we don't have a current version, # we can't return compatibility, return null. return None app_features = app.current_version.features.to_list() return request.feature_profile.has_features(app_features)
def filter_queryset(self, request, queryset, view): if not hasattr(request, "feature_profile"): load_feature_profile(request) if request.feature_profile: must_not = [] for k in request.feature_profile.to_kwargs(prefix="features.has_").keys(): must_not.append(F("term", **{k: True})) if must_not: return queryset.filter(Bool(must_not=must_not)) return queryset
def test_caching_on_request_property(self, from_signature_mock): fake_feature_profile = object() from_signature_mock.return_value = fake_feature_profile request = RequestFactory().get( '/?dev=firefoxos&pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, fake_feature_profile) from_signature_mock.return_value = None load_feature_profile(request) # Should not be None thanks to the property caching. eq_(request.feature_profile, fake_feature_profile)
def filter_queryset(self, request, queryset, view): if not hasattr(request, 'feature_profile'): load_feature_profile(request) if request.feature_profile: must_not = [] for k in request.feature_profile.to_kwargs( prefix='features.has_').keys(): must_not.append(F('term', **{k: True})) if must_not: return queryset.filter(Bool(must_not=must_not)) return queryset
def test_caching_on_request_property(self, from_signature_mock): fake_feature_profile = object() from_signature_mock.return_value = fake_feature_profile request = RequestFactory().get('/?dev=firefoxos&pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, fake_feature_profile) from_signature_mock.return_value = None load_feature_profile(request) # Should not be None thanks to the property caching. eq_(request.feature_profile, fake_feature_profile)
def test_works(self): request = RequestFactory().get( '/?dev=firefoxos&pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile.to_list(), self.profile.to_list())
def test_does_nothing_if_invalid_profile_signature_is_passed(self): request = RequestFactory().get('/?dev=firefoxos&pro=whatever') load_feature_profile(request) eq_(request.feature_profile, None)
def test_does_nothing_without_profile_signature(self): request = RequestFactory().get('/?dev=firefoxos') load_feature_profile(request) eq_(request.feature_profile, None)
def test_does_nothing_on_desktop(self): request = RequestFactory().get('/?dev=desktop&pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile, None)
def test_works(self): request = RequestFactory().get('/?dev=firefoxos&pro=%s' % self.signature) load_feature_profile(request) eq_(request.feature_profile.to_list(), self.profile.to_list())