def app(request): """Session-wide test `Flask` application.""" # Create DB # config = import_string(get_config_name()) # dsn = config.SQLALCHEMY_DATABASE_URI # dsn = dsn[:dsn.rfind('/')] + '/notifier' # Change DB-name # drop_db(dsn) # create_db(dsn) # # Create app # settings_override = { # 'TESTING': True, # 'SQLALCHEMY_DATABASE_URI': dsn # } app = create_app(name=APP_NAME) init_app(app) dsn = app.config['SQLALCHEMY_DATABASE_URI'] drop_db(dsn) create_db(dsn) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() create_tables(app) # Only after context was pushed # Add test client app.client = app.test_client() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def app(request): """Session-wide test `Flask` application.""" # Create DB # config = import_string(get_config_name()) # dsn = config.SQLALCHEMY_DATABASE_URI # dsn = dsn[:dsn.rfind('/')] + '/%s' % APP_NAME.lower() # Change DB-name config = {} # dsn = 'postgresql+psycopg2://yuribro:@localhost:5432/serializer_mixin_test' dsn = 'postgresql+psycopg2://postgres:root!@localhost:5432/serializer_mixin_test' drop_db(dsn) create_db(dsn) # Create app config['TESTING'] = True config['SQLALCHEMY_DATABASE_URI'] = dsn config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app = create_app(name=APP_NAME) app = init_app(app, config=config) # Establish an application context before running the tests. ctx = app.app_context() ctx.push() create_tables(app) # Only after context was pushed # Add test client app.client = app.test_client() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
from IPython import embed from flask import url_for, abort from flasgger import Swagger from webargs.flaskparser import parser from flask_builder import create_app, create_db, is_db_exists, drop_db, init_app, init_mail from lib.utils import ApiException, find_models_and_tables, ujsonify, module_generator logging.basicConfig( level=logging.INFO, format='%(asctime)s | %(message)s', datefmt='%d.%m.%Y %H:%M:%S' ) app = create_app(name='{{cookiecutter.app_name}}') init_app(app) {% if cookiecutter.use_mail == 'y' %} init_mail(app) {% endif %} app.register_error_handler(ApiException, lambda err: err.to_result()) app.config['SWAGGER'] = { 'title': '{{cookiecutter.full_app_name}} API', 'uiversion': 2, 'description': '{{cookiecutter.project_short_description}}', 'termsOfService': '' } swagger = Swagger(app)