def create_app(config_name=None, app=None, config_object=None):
    """
    Create the app with the api blueprint registered
    :param config_name:
    :param app:
    :param config_object:
    :return:
    """
    app = factory.create_app(config_name, app, config_object)

    # Register blueprints, try is incase the blueprint has
    # already been registered on existing app instance
    try:
        app.register_blueprint(API_BLUEPRINT, url_prefix='/api')
        app.add_url_rule('/', 'index', _root)
    except (ValueError, AssertionError):
        pass

    # JWT Setup
    jwt = JWTManager(app)
    jwt._set_error_handler_callbacks(API)  # pylint: disable=W0212

    # Setup JWT Claims
    @jwt.user_claims_loader
    def __add_claims_to_token(identity):
        return jwt_utils.add_claims_to_jwt(identity)

    @app.route('/')
    def root():  # pylint: disable=W0612
        """ Redirect the root endpoint to the api blueprint """
        return redirect('/api')

    return app
Esempio n. 2
0
def test_client():
    """
    test app fixture
    """
    # create app
    app = create_app(environment="testing")
    # yield test app client
    yield app.test_client()
Esempio n. 3
0
def client(request):
    app = create_app(config_mode='Test')
    client = app.test_client()
    headers = {'Accept': 'application/json'}
    client.get = functools.partial(client.get, headers=headers)

    def client_url_for(base, **kwargs):
        with app.test_request_context():
            return url_for('blueprint.{}'.format(base), **kwargs)

    client.url_for = client_url_for
    return client
def client(request):
    app = create_app(config_mode='Test')
    client = app.test_client()
    headers = {'Accept': 'application/json'}
    client.get = partial(client.get, headers=headers)

    def client_url_for(base, **kwargs):
        with app.test_request_context():
            return url_for('blueprint.{}'.format(base), **kwargs)

    client.url_for = client_url_for
    return client
Esempio n. 5
0
from src.factory import create_app
import sys
from src.model import db
from pydblite.sqlite import Database, Table

if __name__ == '__main__':
    app = create_app()
    if sys.argv[-1] == '--init':
        with app.app_context():
            from src.model.billboard import Topics
            from src.model.pydb_pydblite import pydb

            # Use python in-memory class object as database
            #db.create_all()

            from src.controller.index import bp as index_bp
            from src.controller.ajax import bp as ajax_bp
            app.register_blueprint(index_bp)
            app.register_blueprint(ajax_bp, url_prefix='/ajax')

    app.run(debug=True, host='0.0.0.0')
else:
    app = create_app()
Esempio n. 6
0
"""
    wsgi.py: app entry point
"""
import os

from dotenv import load_dotenv

from src.factory import create_app

# load env vars
load_dotenv()
# [OPTIONAL] get GitHub creds to automatically display repos
gh_pat, gh_username = os.environ.get("GH_PAT", None), os.environ.get(
    "GH_USERNAME", None)
# create WSGI app
app = create_app(environment=os.environ.get("ENVIRONMENT", "development"))
# if executed as script (in dev / testing)
if __name__ == "__main__":
    app.run(host=os.environ.get("HOST", "0.0.0.0"),
            port=int(os.environ.get("PORT", 5000)))
Esempio n. 7
0
from src import config, factory, routing


database = factory.create_database(config.MONGODB_CONNSTRING)
api_router = factory.create_api_router(routing.ROUTES)
app = factory.create_app(config.SERVICE_NAME, config.SECRET_KEY, api_router)