def test_load_skips_pending_removal_features(self, client): db.Session.add(features.Feature(name='notification')) db.Session.add(features.Feature(name='abouttoberemoved')) db.Session.flush() client.load() assert client._cache.keys() == ['notification']
def test_remove_old_flag_removes_old_flags(): new_feature = features.Feature(name='notification') old_feature = features.Feature(name='somethingelse') db.Session.add(new_feature, old_feature) db.Session.flush() features.remove_old_flags() remaining = [f.name for f in features.Feature.query.all()] assert remaining == ['notification']
def test_load_skips_database_features_missing_from_dict(self, client): """ Test that load does not load features that are still in the database but not in the FEATURES dict anymore """ db.Session.add(features.Feature(name='notification')) db.Session.add(features.Feature(name='new_homepage')) db.Session.flush() client.load() assert client._cache.keys() == ['notification']
def test_enabled_false_when_staff_true_normal_request( self, client, fetcher): fetcher.return_value = [ features.Feature(name='notification', staff=True) ] assert client.enabled('notification') is False
def test_enabled_true_when_admins_true_admin_request( self, client, fetcher, authn_policy): authn_policy.effective_principals.return_value = [role.Admin] fetcher.return_value = [ features.Feature(name='notification', admins=True) ] assert client.enabled('notification') is True
def test_remove_old_flag_removes_old_flags(): """ The remove_old_flags function should remove unknown flags. New flags and flags pending removal should be left alone, but completely unknown flags should be removed. """ new_feature = features.Feature(name='notification') pending_feature = features.Feature(name='abouttoberemoved') old_feature = features.Feature(name='somethingelse') db.Session.add_all([new_feature, pending_feature, old_feature]) db.Session.flush() features.remove_old_flags() remaining = set([f.name for f in features.Feature.query.all()]) assert remaining == {'abouttoberemoved', 'notification'}
def test_init_skips_database_features_missing_from_dict(self): """ Test that init does not load features that are still in the database but not in the FEATURES dict anymore """ db.Session.add(features.Feature(name='new_homepage')) db.Session.flush() client = self.client() assert len(client._cache) == 0
def test_enabled_false_if_everyone_false(self, client, fetcher): fetcher.return_value = [ features.Feature(name='notification', everyone=False) ] assert client.enabled('notification') is False
def test_load_loads_features(self, client): db.Session.add(features.Feature(name='notification')) db.Session.flush() client.load() assert client._cache.keys() == ['notification']
def test_enabled_true_when_staff_true_staff_request( self, client, authn_policy): client._cache['notification'] = features.Feature(staff=True) authn_policy.effective_principals.return_value = [role.Staff] assert client.enabled('notification') == True
def test_enabled_false_when_staff_true_normal_request(self, client): client._cache['notification'] = features.Feature(staff=True) assert client.enabled('notification') == False
def test_enabled_true_if_everyone_true(self, client): client._cache['notification'] = features.Feature(everyone=True) assert client.enabled('notification') == True
def test_enabled_false_if_everyone_false(self, client): client._cache['notification'] = features.Feature(everyone=False) assert client.enabled('notification') == False
def test_init_skips_pending_removal_features(self): db.Session.add(features.Feature(name='abouttoberemoved')) db.Session.flush() client = self.client() assert len(client._cache) == 0