Esempio n. 1
0
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
Esempio n. 2
0
def app():
    """An application for the tests."""
    _app = create_app(TestConfig)
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Esempio n. 3
0
def app():
    """An application for the tests."""
    _app = create_app('tests.settings')
    ctx = _app.test_request_context()
    ctx.push()

    yield _app

    ctx.pop()
Esempio n. 4
0
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()
Esempio n. 5
0
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
Esempio n. 6
0
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
Esempio n. 7
0
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
Esempio n. 8
0
#!/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`
Esempio n. 9
0
# -*- 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()
Esempio n. 10
0
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, )

Esempio n. 11
0
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)
    # // // // // //
Esempio n. 12
0
def test_app():
    """Create test app instance."""

    return create_app(TestConfig)
Esempio n. 13
0
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']
Esempio n. 14
0
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)
Esempio n. 15
0
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()
Esempio n. 16
0

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)
Esempio n. 17
0
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