def app(): test_app = create_app('TestConfig') with test_app.app_context(): # alternative pattern to app.app_context().push() # all commands indented under 'with' are run in the app context db.create_all() yield test_app db.session.remove() db.drop_all()
def test_create_app(): test_app, test_db = create_app() assert type( test_app) == MyServer, 'Should ensure app is of the correct type' assert type( test_db) == pd.DataFrame, 'Should ensure db is of the correct type' assert test_app.config.get( 'DATABASE_ZIP_FILENAME' ) == DATABASE_ZIP_FILENAME, 'Should have correct DATABASE_ZIP_FILENAME value' assert test_app.config.get( 'CSRF_ENABLED') == False, 'Should have correct CSRF_ENABLED value' assert len(test_app.config.get('CSRF_SESSION_KEY')) == len( os.urandom(24)), 'Should have correct CSRF_SESSION_KEY type' assert len(test_app.config.get('SECRET_KEY')) == len( os.urandom(24)), 'Should have correct SECRET_KEY type' assert test_app.config.get( 'LOG_FILE') == 'api.log', 'Should have correct LOG_FILE value'
from API import create_app app = create_app('config.Config') if __name__ == '__main__': app.run(debug=True)
# coding=utf-8 from API import create_app, db from API.models import User, Task from flask.ext.script import Manager, Shell from flask.ext.migrate import Migrate, MigrateCommand app = create_app('default') manager = Manager(app) Migrate = Migrate(app, db) def make_shell_context(): return dict(app=app, db=db, User=User, Task=Task) manager.add_command("shell", Shell(make_context=make_shell_context)) manager.add_command('db', MigrateCommand) if __name__ == '__main__': manager.run()
from flask_script import Manager from API import create_app # set up the app app, db = create_app() manager = Manager(app) @manager.command def rundev(): app.run(debug=True, host="0.0.0.0", port=5000) @manager.command def runserver(): app.run(debug=False) if __name__ == "__main__": manager.run()
#!/usr/bin/env python3 import os import shutil import pytest from flask_migrate import Migrate, MigrateCommand from flask_script import Manager from API import create_app from API.models import db app = create_app() db.init_app(app) migrate = Migrate(app, db) manager = Manager(app) manager.add_command('db', MigrateCommand) @manager.command def test(): ''' Run Tests Create test upload folders if they do not exist. Remove folders after tests finished running. ''' test_upload_folder = '/home/fareed/Documents/Kreoh/test_kreoh_user_site_images' if not os.path.exists(test_upload_folder): os.makedirs(test_upload_folder)
import os from API import create_app settings_module = os.getenv('APP_SETTINGS_MODULE') app = create_app(settings_module)
def test_production_create_app(): test_app, _ = create_app(test_config=config['prod']) assert test_app.config.get( 'DEBUG') == False, 'Should have correct DEBUG value for production'
def test_development_create_app(): test_app, _ = create_app(test_config=config['dev']) assert test_app.config.get( 'DEBUG') == True, 'Should have correct DEBUG value for development'
from API import create_app from API.configuration import Development app = create_app(Development) if app.config['STATUS'] == 'PRODUCTION': context = ('cert/cert.pem', 'cert/key.pem') app.run(host=app.config['HOST'], port=app.config['PORT'], ssl_context=context) else: app.run(host=app.config['HOST'], port=app.config['PORT'])
from API import create_app application = create_app()