def remove_old_flags(event): """Remove old feature flags from the database.""" # Skip this if we're in a script, not actual app startup. See the comment # in h.cli:main for an explanation. if 'H_SCRIPT' in os.environ: return engine = db.make_engine(event.app.registry.settings) session = db.Session(bind=engine) Feature.remove_old_flags(session) session.commit() session.close() engine.dispose()
def test_all_only_returns_current_flags(self, db_session): """The .all() method should only return named current feature flags.""" new, pending, old = [ Feature(name='notification'), Feature(name='abouttoberemoved'), Feature(name='somethingelse') ] db_session.add_all([new, pending, old]) db_session.flush() features = Feature.all(db_session) assert len(features) == 1 assert features[0].name == 'notification'
def test_remove_old_flag_removes_old_flags(self, db_session): """ 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, pending, old = [Feature(name='notification'), Feature(name='abouttoberemoved'), Feature(name='somethingelse')] db_session.add_all([new, pending, old]) db_session.flush() Feature.remove_old_flags(db_session) remaining = set([f.name for f in db_session.query(Feature).all()]) assert remaining == {'abouttoberemoved', 'notification'}
def test_remove_old_flag_removes_old_flags(self, db_session): """ 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, pending, old = [ Feature(name='notification'), Feature(name='abouttoberemoved'), Feature(name='somethingelse') ] db_session.add_all([new, pending, old]) db_session.flush() Feature.remove_old_flags(db_session) remaining = set([f.name for f in db_session.query(Feature).all()]) assert remaining == {'abouttoberemoved', 'notification'}
def test_all_only_returns_current_flags(self, db_session): """The .all() method should only return named current feature flags.""" new, pending, old = [Feature(name='notification'), Feature(name='abouttoberemoved'), Feature(name='somethingelse')] db_session.add_all([new, pending, old]) db_session.flush() features = Feature.all(db_session) assert len(features) == 1 assert features[0].name == 'notification'
def fetcher(self, cohort): return mock.Mock(spec_set=[], return_value=[ Feature(name='foo'), Feature(name='bar'), Feature(name='on-for-everyone', everyone=True), Feature(name='on-for-staff', staff=True), Feature(name='on-for-admins', admins=True), Feature(name='on-for-cohort', cohorts=[cohort]) ])
def test_all_creates_annotations_that_dont_exist(self, db_session): features = Feature.all(db_session) assert len(features) == 1 assert features[0].name == 'notification'
def test_description_returns_hardcoded_description(self): feat = Feature(name='notification') assert feat.description == 'A test flag for testing with.'