def setUp(self): app.config.from_object('config.TestingConfig') self.client = app.test_client() with app.app_context(): init_app() user_datastore.create_user(email='test', password=encrypt_password('test')) db.session.commit()
def pytest_sessionstart(session): """ before session.main() is called. """ app = server.init_app() app.config["TESTING"] = True # push the app_context ctx = app.app_context() ctx.push() logging.disable(logging.DEBUG)
def __init__(self, *args, **kwargs): super(APITest, self).__init__(*args, **kwargs) app_kwargs = {'model_type': 'bert-base-cased', 'dim': 768} self.client = init_app(**app_kwargs).test_client() self.data = { 'documents': [ 'Super Mario Bros., one of the most influential and best-selling video games of all time,' ' was first released for the Nintendo Entertainment System in Japan.', 'Scientists confirm the first detection, using gravitational-wave astronomy, of a ' 'black hole in the upper mass gap.', 'As of 13 September 2020, more than 28.7 million cases have been reported worldwide; more ' 'than 920,000 people have died and more than 19.4 million have recovered.', ] }
def main(): app = init_app(Config) app.run(host='0.0.0.0')
from server import init_app app = init_app()
from server import init_app from config import Config if __name__ == "__main__": app = init_app(Config) app.run(debug=True)
def app(): app = server.init_app() app.config["TESTING"] = True app.config["WTF_CSRF_ENABLED"] = False return app
from fastapi.testclient import TestClient from app.db import init_databases, shutdown_databases from app.settings import CONFIG from server import init_app app = init_app(use_sentry=False) @app.on_event("startup") async def startup(): await init_databases(CONFIG) @app.on_event("shutdown") async def shutdown(): await shutdown_databases() def test_self_check(): with TestClient(app) as client: response = client.get("/stock_news/self_check/") assert response.status_code == 200 print(response.json()) assert response.json() == {"status": "Ok"}
@babel.localeselector def get_locale(): return { 'zh_CN': 'zh_Hans_CN', 'en': 'en' }.get(request.accept_languages.best_match(['zh_CN', 'en'])) @app.route('/', methods=['GET', 'POST']) def index(): return render_template('index.html') @app.route('/android', methods=['GET', 'POST']) def android(): return render_template('android.html', locale=get_locale()) @app.route('/history', methods=['GET', 'POST']) def history(): return render_template('history.html') if __name__ == '__main__': from server import init_app socketio = init_app(app) socketio.run(app, port=5500)
def cli(loop, aiohttp_client): app = loop.run_until_complete(init_app()) return loop.run_until_complete(aiohttp_client(app))
from server import create_app, init_app from config import Config as conf app = create_app(conf) with app.app_context(): init_app(app)