#!/usr/bin/env python # pylint: disable=import-error """ Save all collections to update calculated fields. """ import os from crowdsorter.settings import get_config from crowdsorter.factory import create_app from crowdsorter.models import Collection create_app(get_config(os.getenv('FLASK_ENV') or 'dev')) for collection in Collection.objects: collection.save()
import os from flask_script import Manager, Server from crowdsorter.settings import get_config from crowdsorter.factory import create_app def find_assets(): """Yield paths for all static files and templates.""" for name in ['static', 'templates']: directory = os.path.join(app.config['PATH'], name) for entry in os.scandir(directory): if entry.is_file(): yield entry.path config = get_config(os.getenv('FLASK_ENV')) app = create_app(config) server = Server(extra_files=find_assets()) manager = Manager(app) manager.add_command('run', server) if __name__ == '__main__': manager.run()
def when_valid(): config = get_config('prod') expect(config.ENV) == 'prod'
def when_unknown(): with expect.raises(AssertionError): get_config('unknown')
def when_empty(): with expect.raises(AssertionError): get_config('')
def app(): return create_app(get_config('test'))