def main(): logging.basicConfig( format='%(message)s', stream=sys.stdout, level=logging.DEBUG ) structlog.configure( processors=[ structlog.stdlib.add_log_level, structlog.stdlib.add_logger_name, structlog.processors.KeyValueRenderer( key_order=["event", "request_id"] ) ], context_class=structlog.threadlocal.wrap_dict(dict), logger_factory=structlog.stdlib.LoggerFactory() ) app = create_app() # allows us to view metrics on /metrics dispatcher = DispatcherMiddleware(app.wsgi_app, {'/metrics': make_wsgi_app()}) run_simple( 'localhost', 5000, dispatcher, use_reloader=True, )
def setUp(self): self.app = create_app('testing') self.app_context = self.app.app_context() self.app_context.push() self.client = self.app.test_client() db.create_all() Permission.create_permissions()
def app(): app = create_app({'TESTING': True}) # See https://stackoverflow.com/a/36222848/4241180, allows # test_client() to work as expected app.wsgi_app = DispatcherMiddleware(app.wsgi_app, {'/metrics': make_wsgi_app()}) yield app # teardown user_db.clear()
def app(request): """ App fixture :param request: :return app: """ settings_override = { 'TESTING': True, 'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI, 'PRESERVE_CONTEXT_ON_EXCEPTION': False, } app = create_app(settings_override) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
from flask_testing import TestCase from users import create_app, db app = create_app() class BaseTestCase(TestCase): def create_app(self): app.config.from_object('users.config.TestingConfig') return app def setUp(self): db.create_all() db.session.commit() def tearDown(self): db.session.remove() db.drop_all()
#!/usr/bin/env python import os if os.path.exists('.env'): print('Importing environment from .env...') for line in open('.env'): var = line.strip().split('=') if len(var) == 2: os.environ[var[0]] = var[1] from users import create_app, db from flask_script import Manager, Shell from flask_migrate import Migrate, MigrateCommand app = create_app(os.getenv('FLASK_CONFIG') or 'default') manager = Manager(app) migrate = Migrate(app, db) def make_shell_context(): return dict(app=app, db=db) manager.add_command("shell", Shell(make_context=make_shell_context)) manager.add_command('db', MigrateCommand) @manager.command def test(coverage=False): """ Run the unit tests and pep8 checks """ from subprocess import call call(["python","-m","pytest","test"])
import os from users import create_app app = create_app(os.getenv('FLASK_CONFIG') or 'development') if __name__ == "__main__": app.run()