def flask_app(request): flask_app = create_app({'TESTING': True}) context = flask_app.app_context() context.push() flask_app.debug = True yield flask_app context.pop()
from flask_migrate import Migrate, upgrade import click import os import simplejson as json from web_service import create_app from web_service import socketio from web_service.database import db from web_service.models.person import Person from web_service.models.swipe import Swipe dotenv_path = os.path.join('config', '.env') load_dotenv(dotenv_path) flask_app = create_app(os.getenv('FLASK_CONFIG') or None) migrate = Migrate(flask_app, db) @flask_app.shell_context_processor def make_shell_context(): return dict(app=flask_app, db=db, Person=Person, Swipe=Swipe) @flask_app.cli.command() def runserver(): """Run the web-server.""" from web_service.database import db_engine if not db_engine.dialect.has_table(db_engine, 'alembic_version'): initialize_database()
import os from web_service import create_app PORT = int(os.getenv('PORT', '80')) app = create_app() app.run(host='0.0.0.0', port=PORT, threaded=True)
# -*- coding: utf-8 -*- from flask_migrate import Migrate from web_service import create_app, db app = create_app('development') # @app.shell_context_processor # def make_shell_context(): # """ # go in flask shell to use the instance # :return: # """ # return dict(db=db, APIData=api_store) # @app.route('/') def index(): html = """ <a href='/api/'>API index</a> """ return html
import eventlet import json import pgpubsub import re from flask import Blueprint from web_service import create_app, socketio from web_service.config import configure_app eventlet.monkey_patch() bp = Blueprint('pg_pubsub_client', __name__) flask_app = create_app() @bp.before_app_first_request def start_listener(): eventlet.spawn(pg_listen_thread) def pg_listen_thread(): with flask_app.app_context(): configure_app(flask_app) pubsub = pgpubsub.connect( dbname=flask_app.config['DATABASE_NAME'], user=flask_app.config['DATABASE_USERNAME'], password=flask_app.config['DATABASE_PASSWORD'], host=flask_app.config['DATABASE_HOSTNAME'], port=flask_app.config['DATABASE_PORT']) pubsub.listen('table_update')
def setUp(self): app_settings = 'config.TestingConfig' self.app = create_app() self.app.config.from_object(app_settings) with self.app.app_context(): self.app.testing = True
def setUp(self): self.app = create_app() with self.app.app_context(): self.app.testing = True self.client = self.app.test_client()
def client(): client = create_app() return client.test_client()