async def test_blueprint_url_prefix(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)
    prefix = Blueprint('prefix', __name__, url_prefix='/prefix')

    @app.route('/page/')
    @blueprint.route('/page/')
    @prefix.route('/page/')
    async def route() -> ResponseReturnValue:
        return 'OK'

    app.register_blueprint(blueprint, url_prefix='/blueprint')
    app.register_blueprint(prefix)

    async with app.test_request_context('GET', '/'):
        assert '/page/' == url_for('route')
        assert '/prefix/page/' == url_for('prefix.route')
        assert '/blueprint/page/' == url_for('blueprint.route')

    async with app.test_request_context('GET', '/page/'):
        assert request.blueprint is None

    async with app.test_request_context('GET', '/prefix/page/'):
        assert request.blueprint == 'prefix'

    async with app.test_request_context('GET', '/blueprint/page/'):
        assert request.blueprint == 'blueprint'
async def test_root_endpoint_blueprint(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)

    @blueprint.route('/page/')
    async def route() -> ResponseReturnValue:
        return 'OK'

    app.register_blueprint(blueprint)
    async with app.test_request_context('GET', '/page/'):
        assert request.blueprint == 'blueprint'
        assert '/page/' == url_for('blueprint.route')
async def test_blueprint_error_handler(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)

    @blueprint.route('/error/')
    async def error() -> None:
        abort(409)
        return 'OK'

    @blueprint.errorhandler(409)
    async def handler(_: Exception) -> ResponseReturnValue:
        return 'Something Unique', 409

    app.register_blueprint(blueprint)

    response = await app.test_client().get('/error/')
    assert response.status_code == 409
    assert b'Something Unique' in (await response.get_data())
async def test_openapi_blueprint_noprefix(app: Pint) -> None:
    blueprint = PintBlueprint('blueprint', __name__)

    @blueprint.route('/')
    class Testing(Resource):
        async def get(self):
            return 'GET'

    app.register_blueprint(blueprint)

    client = app.test_client()
    response = await client.get('/openapi.json')
    assert response.status_code == HTTPStatus.OK

    openapi = await response.get_json()
    assert openapi['paths'].get('/', None) is not None
    assert openapi['paths']['/'].get('get', None) is not None
async def test_blueprint_method_view(app: Pint) -> None:
    blueprint = Blueprint('blueprint', __name__)

    class Views(MethodView):
        async def get(self) -> ResponseReturnValue:
            return 'GET'

        async def post(self) -> ResponseReturnValue:
            return 'POST'

    blueprint.add_url_rule('/', view_func=Views.as_view('simple'))
    app.register_blueprint(blueprint)

    test_client = app.test_client()
    response = await test_client.get('/')
    assert 'GET' == (await response.get_data(raw=False))
    response = await test_client.post('/')
    assert 'POST' == (await response.get_data(raw=False))
async def test_blueprint_resource(app: Pint) -> None:
    blueprint = PintBlueprint('blueprint', __name__)

    @blueprint.route('/testing')
    class Testing(Resource):
        async def get(self):
            return 'GET'

        async def post(self):
            return 'POST'

    app.register_blueprint(blueprint)

    client = app.test_client()
    response = await client.post('/testing')
    assert 'POST' == (await response.get_data(raw=False))
    response = await client.get('/testing')
    assert 'GET' == (await response.get_data(raw=False))
async def test_openapi_with_blueprint(app: Pint) -> None:
    blueprint = PintBlueprint('blueprint', __name__, url_prefix='/blueprint')

    @app.route('/testing')
    @blueprint.route('/testing')
    class Testing(Resource):
        async def get(self):
            return 'GET'

        async def post(self):
            return 'POST'

    app.register_blueprint(blueprint)

    client = app.test_client()
    response = await client.get('/openapi.json')
    assert response.status_code == HTTPStatus.OK

    openapi = await response.get_json()
    assert len(openapi['paths'].keys()) == 2
Ejemplo n.º 8
0
def create_app(config) -> Pint:
    load_dotenv(verbose=True)

    app = Pint(__name__,
               title="BattleShip",
               base_model_schema=BASE_MODEL_SCHEMA)
    app = cors(app, allow_origin="*")
    app.json_encoder = Encoder

    app.config.from_envvar("CONFIG_FILE")

    app.games = dict()

    @app.before_serving
    async def init_orm():
        await init()

    from battlefield.session.data.api.single import session
    app.register_blueprint(session)

    from battlefield.session.data.api.multi import sessions
    app.register_blueprint(sessions)

    from battlefield.game.data.websocket import game
    app.register_blueprint(game)

    @app.cli.command()
    def openapi():
        print(json.dumps(app.__schema__, indent=4, sort_keys=False))

    @app.after_serving
    async def close_orm():
        await Tortoise.close_connections()

    return app
Ejemplo n.º 9
0
        "quart.serving": {
            "level": "DEBUG"
        },
        "stocks.stocks": {
            "level": "INFO"
        },
    },
})

app = Pint(__name__, title="Stock Analysis")

app.config["TEMPLATES_AUTO_RELOAD"] = True
app.config["STOCKS_FOLDER"] = os.path.join(app.static_folder, "stocks")
blueprint.stocks_folder = os.path.join(app.static_folder, "stocks")

app.register_blueprint(blueprint)


@app.route("/", methods=["GET", "POST"], provide_automatic_options=False)
class Root(Resource):
    async def get(self):
        return await render_template("index.html")


status_expected_schema = app.create_validator("status", {
    "type": "object",
    "properties": {
        "status": {
            "type": "string",
        },
    },
Ejemplo n.º 10
0
def register_blueprints(app: Pint) -> None:
    base_bp = import_module("app.base").bp
    app.register_blueprint(base_bp)

    api_bp = import_module("app.api").bp
    app.register_blueprint(api_bp)
async def test_pint_blueprint_openapi(app: Pint) -> None:
    blueprint = PintBlueprint('blueprint', __name__, url_prefix='/blueprint')
    app.register_blueprint(blueprint)

    async with app.test_request_context('GET', '/'):
        assert '/openapi.json' == url_for('openapi')
Ejemplo n.º 12
0
async def test_pint_blueprint_openapi(app: Pint, req_ctx) -> None:
    blueprint = PintBlueprint('blueprint', __name__, url_prefix='/blueprint')
    app.register_blueprint(blueprint)

    async with req_ctx(app, '/', method='GET'):
        assert '/openapi.json' == url_for('openapi')
Ejemplo n.º 13
0
""":mod:'irastretto.web.app'
--- Quart application

Todo:
    * Download Queue (Modular Structure).
    * Download images from Twitter (Queue Module).
    * Caching duplicated reference.
    * Extract Zelda.
    * User login.
    * Accounts Management.
    * Download images from Pixiv (Queue Module).
    * Library interface.
    * Audio/Video Play.
    * Share Timeline.
    * Finder Extension (Another Project).
"""

from quart_openapi import Pint
from quart_cors import cors

from . import blueprints
from .. import config

app = Pint(__name__, title='Irastretto', template_folder='templates')
app = cors(app)
# app.config.from_object()

app.register_blueprint(blueprints.root.blueprint)
app.register_blueprint(blueprints.tasks.blueprint)
app.register_blueprint(blueprints.users.blueprint)
Ejemplo n.º 14
0
import quart.flask_patch
from dotenv import load_dotenv
from quart_jwt_extended import JWTManager
from quart_openapi import Pint

from libs.db import db
from libs.password import psw
from models.users import TokenBlacklist
from resources.user_confirmation import user_confirm
from resources.users import user

app = Pint(__name__)

# Register Blueprints
app.register_blueprint(user)
app.register_blueprint(user_confirm)


load_dotenv('.env', verbose=True)
app.config.from_object('default_config')
app.config.from_envvar('APPLICATION_SETTINGS')
jwt = JWTManager(app)


@app.before_first_request
async def create_tables():
    async with app.app_context():
        db.create_all()