def test_production_config(): """Production config.""" app = create_app(ProdConfig) assert app.config['ENV'] == 'prod' assert app.config['DEBUG'] is False assert app.config['DEBUG_TB_ENABLED'] is False assert app.config['ASSETS_DEBUG'] is False
def app(): """An application for the tests.""" _app = create_app(TestConfig) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def app(): """An application for the tests.""" _app = create_app('tests.settings') ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def app(): """Create application for the tests.""" _app = create_app("tests.settings") _app.logger.setLevel(logging.CRITICAL) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()
def plain_client(): load_dotenv() app = create_app('testing') with app.test_client() as client: with app.app_context(): db.init_app(app) db.drop_all() db.create_all() yield client
def login_client(): """ This fixture create the database consisting one user :return: """ load_dotenv() app = create_app('testing') with app.test_client() as client: with app.app_context(): db.init_app(app) db.drop_all() db.create_all() create_user(email='*****@*****.**', password='******') yield client
def auth_client(): """ This fixture provide a authorized client, with some initial database :return: """ load_dotenv() app = create_app('testing') with app.test_client() as client: with app.app_context(): db.init_app(app) db.drop_all() db.create_all() user_id = create_test_db() access_token = create_access_token(identity=user_id) client.environ_base[ 'HTTP_AUTHORIZATION'] = 'Bearer ' + access_token yield client
#!/usr/bin/env python # coding=utf-8 # import Flask Script object from werkzeug.security import generate_password_hash from flask_script import Manager, Server from flask_migrate import Migrate, MigrateCommand from main.app import db, create_app from main.model import User from main.api.files import EntryFileTemplate # Init manager object via app object app = create_app() manager = Manager(app) # Create a new commands: server # This command will be run the Flask development_env server manager.add_command("run_server", Server(host="0.0.0.0", port=5000)) migrate = Migrate(app, db) manager.add_command("db", MigrateCommand) @manager.shell def make_shell_context(): """Create a python CLI. return: Default import object type: `Dict`
# -*- coding: utf-8 -*- """Create an application instance.""" from flask.helpers import get_debug_flag from main.app import create_app from main.settings import DevConfig, ProdConfig CONFIG = DevConfig if get_debug_flag() else ProdConfig app = create_app(CONFIG) app.app_context().push()
from aiohttp import web import logging from main.app import create_app from main.settings import load_config app = create_app(config=load_config()) # logging.basicConfig(level=logging.DEBUG) if __name__ == '__main__': web.run_app(app, )
import sys sys.path.append('.') from main.app import create_app app = create_app(name='app') if __name__ == '__main__': # cobra-55555 -20-04-13 app.run(host='0.0.0.0', port=5000) # // // // // //
def test_app(): """Create test app instance.""" return create_app(TestConfig)
import json from main.app import create_app from main.model import Om app = create_app('testing') app_ctx = app.app_context() app_ctx.push() test_app = app.test_client() @app.before_first_request def other_config(): _om = Om.query.filter().first() app.config.update(break_up_fee=_om.break_up_fee, tax_free_rate=_om.tax_free_rate, ware_fare=_om.ware_fare) class AuthUser(object): def __init__(self, user_name, password="******"): response = test_app.post('/api/v1/auth/token', json={ 'username': user_name, 'password': password }) if not response.status_code == 200: raise Exception('cant get token' + response.text) result = json.loads(response.get_data(as_text=True)) self.token = result['token']
from dotenv import load_dotenv from main.app import create_app from main.db import db load_dotenv() app = create_app('development') db.init_app(app) @app.before_first_request def create_tables(): db.create_all() # create the data.db unless it's already existed if __name__ == '__main__': app.run(port=5000, debug=False)
from flask_script import Manager from main.app import create_app application = create_app("main") application.config['DEBUG'] = True manager = Manager(application) @manager.command def hello(): print("hello") if __name__ == "__main__": manager.run()
class ReverseProxied(object): def __init__(self, app, script_name=None, scheme=None, server=None): self.app = app self.script_name = script_name self.scheme = scheme self.server = server def __call__(self, environ, start_response): script_name = environ.get('HTTP_X_SCRIPT_NAME', '') or self.script_name if script_name: environ['SCRIPT_NAME'] = script_name path_info = environ['PATH_INFO'] if path_info.startswith(script_name): environ['PATH_INFO'] = path_info[len(script_name):] scheme = environ.get('HTTP_X_SCHEME', '') or self.scheme if scheme: environ['wsgi.url_scheme'] = scheme server = environ.get('HTTP_X_FORWARDED_SERVER', '') or self.server if server: environ['HTTP_HOST'] = server return self.app(environ, start_response) app = create_app(ProdConfig) app.wsgi_app = ReverseProxied(app.wsgi_app, script_name='/flask') if __name__ == "__main__": app.run(port=8000)
def test_dev_config(): """Development config.""" app = create_app(DevConfig) assert app.config['ENV'] == 'dev' assert app.config['DEBUG'] is True assert app.config['ASSETS_DEBUG'] is True