コード例 #1
0
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
コード例 #2
0
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))
コード例 #3
0
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
コード例 #4
0
from battlefield.game.domain.use_cases.game_status_getter import (
    GetterRepository,
    StatusGetter,
)

logger = logging.getLogger(__name__)
formatter = logging.Formatter(
    "[%(asctime)s][%(levelname)s] %(name)s: %(message)s"
)
consoleHandler = logging.StreamHandler(sys.stdout)
consoleHandler.setFormatter(formatter)
logger.setLevel(logging.INFO)
logger.addHandler(consoleHandler)


game = PintBlueprint("game", "game")


class WebsocketResponder(ResponderClient):
    def send_to(self, player: Player, msg: str) -> Any:
        if player.ws:
            return player.ws.send(msg)


def collect_websocket(func):
    async def wrapper(session_id, *args, **kwargs):
        if session_id not in current_app.games:
            current_app.games[session_id] = []

        cur_game = current_app.games[session_id]
コード例 #5
0
ファイル: __init__.py プロジェクト: noxowl/irastretto
""":mod:'irastretto.web.blueprints.root'

"""

from quart import g, request, render_template, jsonify
from quart_openapi import PintBlueprint, Resource

from irastretto.services import info

blueprint = PintBlueprint('root', __name__, template_folder='templates')


@blueprint.route('/')
class Root(Resource):
    async def get(self):
        return await render_template('index.html')


@blueprint.route('/about')
class About(Resource):
    async def get(self):
        return await render_template('about.html')


@blueprint.route('/info')
class Info(Resource):
    async def get(self):
        result = info()
        return jsonify(result)
コード例 #6
0
from quart import jsonify
from quart_openapi import Resource, PintBlueprint

session = PintBlueprint("session", "session")


@session.route("/sessions/<int:id>")
class Session(Resource):
    async def get(self, id):
        return jsonify({})
コード例 #7
0
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')
コード例 #8
0
""":mod:'irastretto.web.blueprints.users'

"""
from quart import g, request
from quart_openapi import PintBlueprint, Resource

blueprint = PintBlueprint('users', __name__)


@blueprint.route('/users/<user_id>')
class User(Resource):
    async def get(self, user_id):
        return user_id
コード例 #9
0
""":mod:'irastretto.web.blueprints.tasks'

"""
from quart import g, request, jsonify
from quart_openapi import PintBlueprint, Resource

from irastretto.services import extractor
from .models import taskVaildator

blueprint = PintBlueprint('tasks', __name__)

TaskValidator = blueprint.create_validator('task_request', taskVaildator)


@blueprint.route('/tasks')
class Tasks(Resource):
    @blueprint.expect(TaskValidator)
    async def post(self) -> dict:
        result = extractor.extract(resource=await request.json)
        return jsonify(result)


@blueprint.route('/tasks/<string:task_id>')
class ExistTasks(Resource):
    async def get(self, task_id):
        return jsonify(task_id)
コード例 #10
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')
コード例 #11
0
import time
import traceback

from libs.mailgun import MailgunException
from models.user_confirmation import UserConfirmationModel
from models.users import UserModel
from quart import make_response, render_template
from quart_openapi import PintBlueprint, Resource
from schema.user_confirmation import UserConfirmationSchema
from strings.constants import (CONFIRMATION_TOKEN_NOT_FOUND, EXPIRED_TOKEN,
                               TOKEN_ALREADY_CONFIRMED, RESEND_SUCCESSFULL,
                               USER_NOT_FOUND, RESEND_FAILED)

user_confirm = PintBlueprint("user_confirm", __name__)


@user_confirm.route("/user_confirm")
@user_confirm.route("/user_confirm/<string:confirmation_id>")
class UserConfirm(Resource):
    async def get(self, confirmation_id: str):

        confirmation = UserConfirmationModel.find_by_id(confirmation_id)

        if not confirmation:
            return {'message': CONFIRMATION_TOKEN_NOT_FOUND}, 404

        if confirmation.token_expires_at < int(time.time()):
            return {'message': EXPIRED_TOKEN}, 400

        if confirmation.confirmed:
            return {'message': TOKEN_ALREADY_CONFIRMED}, 400
コード例 #12
0
from quart_openapi import PintBlueprint

bp = PintBlueprint(
    'api',
    __name__,
    url_prefix='/api',
)

from app.api.routes import cars
from app.api.routes import clients
from app.api.routes import orders
コード例 #13
0
ファイル: stocks.py プロジェクト: ajmal017/StockAnalysis-2
logging.basicConfig(
    format="[%(asctime)s.%(msecs)03d] %(levelname)s:%(name)s: %(message)s",
    level=logging.DEBUG,
    datefmt="%Y-%m-%d %H:%M:%S",
    stream=sys.stderr,
)
logger = logging.getLogger(__name__)


def not_found():
    logger.error("Something happend!")
    return jsonif({"detail": "Not Found!"})


blueprint = PintBlueprint("stocks", __name__)
blueprint.register_error_handler(404, not_found)

DOWNLOAD = "download"
LIST = "list"
MAX_DAY_INCREASE = "max_day_increase"
REFRESH = "refresh"
# todo add constants

# def print_table(symbol, convtype):
#     collection = stock_collection.StockCollection()
#     collection.load()

#     if convtype == "list":
#         collection.list()
コード例 #14
0
from http import HTTPStatus

from quart import jsonify
from quart_openapi import Resource, PintBlueprint

from battlefield.session.domain.use_cases.creator import SessionCreator
from battlefield.session.domain.use_cases.lister import SessionLister
from battlefield.session.data.data_access import SessionDataAccess
from battlefield.session.data.presenters import SessionPresenter

sessions = PintBlueprint("sessions", "sessions")

resp_obj = sessions.create_validator("response", {"type": "Session"})
resp_list = sessions.create_validator("response", {
    "type": "array",
    "items": {
        "type": "Session"
    }
})


@sessions.route("/sessions")
class Sessions(Resource):
    @sessions.response(HTTPStatus.OK, "OK", resp_obj)
    async def post(self):
        saver = SessionDataAccess()
        creation_result = await SessionCreator(saver).create()
        result = SessionPresenter(creation_result).to_dict()
        return jsonify(result)

    @sessions.response(HTTPStatus.OK, "OK", resp_list)
コード例 #15
0
from models.user_confirmation import UserConfirmationModel
from models.users import TokenBlacklist, UserModel
from quart import request
from quart_jwt_extended import (create_access_token, create_refresh_token,
                                fresh_jwt_required, get_jwt_identity,
                                get_raw_jwt, jwt_refresh_token_required)
from quart_openapi import PintBlueprint, Resource
from requests_async.adapters import ConnectionError
from schema.users import (EmailSchema, LocationSchema, PasswordSchema,
                          UserLoginSchema, UsernameSchema, UserSchema)
from strings.constants import (ACCOUNT_UPDATED, EMAIL_TAKEN, EMAIL_UPDATED,
                               INCORRECT_EMAIL_OR_PASSWORD, LOGGED_OUT,
                               NOT_ACTIVATED, USER_CREATED, USER_DELETED,
                               USER_NOT_FOUND)

user = PintBlueprint("user", __name__)
user_schema = UserSchema(load_only=(
    'password',
    'id',
))
login_schema = UserLoginSchema()


@user.route("/users/<name>")
class User(Resource):
    @classmethod
    @jwt_refresh_token_required
    async def get(cls, name):
        get_user = await UserModel.find_user_by_name(name)
        if not get_user:
            return {'message': USER_NOT_FOUND}, 404