Beispiel #1
0
async def get_bot_chats(request: requests.Request) -> responses.Response:
    """Return list of bot chats.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
         List of bot chats.
    """
    payload = chat_list.ChatList.parse_obj(request.query_params)
    add_request_to_collection(request, payload)

    inserted_at = dt.fromisoformat("2019-08-29T11:22:48.358586+00:00")
    updated_at = dt.fromisoformat("2019-09-29T10:30:48.358586+00:00")
    return PydanticResponse(
        APIResponse[chats.BotChatList](result=chats.BotChatList(__root__=[
            chats.BotChatFromList(
                name="chat name",
                description="test",
                chat_type=enums.ChatTypes.group_chat,
                group_chat_id=uuid.uuid4(),
                members=[uuid.uuid4()],
                inserted_at=inserted_at,
                updated_at=updated_at,
            ),
        ], ), ), )
Beispiel #2
0
async def get_info(request: requests.Request) -> responses.Response:
    """Handle retrieving information of chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with information of chat.
    """
    payload = info.Info.parse_obj(request.query_params)
    add_request_to_collection(request, payload)

    inserted_ad = dt.fromisoformat("2019-08-29T11:22:48.358586+00:00")
    return PydanticResponse(
        APIResponse[chats.ChatFromSearch](result=chats.ChatFromSearch(
            name="chat name",
            chat_type=enums.ChatTypes.group_chat,
            creator=uuid.uuid4(),
            group_chat_id=payload.group_chat_id,
            members=[
                users.UserFromChatSearch(
                    user_huid=uuid.uuid4(),
                    user_kind=enums.UserKinds.user,
                    admin=True,
                ),
            ],
            inserted_at=inserted_ad,
        ), ), )
Beispiel #3
0
async def post_notification(request: Request) -> Response:
    """Handle pushed notification request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with sync_id of pushed message.
    """
    payload = Notification.parse_obj(await request.json())
    add_message_to_collection(request, payload)
    return PydanticResponse(APIResponse[str](result="notification_pushed"))
Beispiel #4
0
async def post_reply_event(request: Request) -> Response:
    """Handle reply event request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Empty json response.
    """
    payload = ReplyEvent.parse_obj(await request.json())
    add_message_to_collection(request, payload)
    return PydanticResponse(APIResponse[str](result="reply_pushed"))
Beispiel #5
0
async def post_add_user(request: requests.Request) -> responses.Response:
    """Handle adding of user to chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of adding.
    """
    payload = add_user.AddUser.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Beispiel #6
0
async def post_add_admin_role(request: requests.Request) -> responses.Response:
    """Handle promoting users to admins request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of adding.
    """
    payload = add_admin_role.AddAdminRole.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Beispiel #7
0
async def post_stealth_set(request: requests.Request) -> responses.Response:
    """Handle stealth enabling in chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of enabling stealth.
    """
    payload = stealth_set.StealthSet.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[bool](result=True))
Beispiel #8
0
async def get_token(request: Request) -> Response:
    """Handle retrieving token from BotX API request.

    Arguments:
        request: starlette request for route.

    Returns:
        Return response with new token.
    """
    request_data = {**request.path_params, **request.query_params}
    payload = Token(**request_data)
    add_request_to_collection(request, payload)
    return PydanticResponse(APIResponse[str](result="real token"))
Beispiel #9
0
async def get_by_email(request: Request) -> Response:
    """Handle retrieving information about user request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with information about user.
    """
    payload = ByEmail.parse_obj(request.query_params)
    add_request_to_collection(request, payload)
    return PydanticResponse(
        APIResponse[UserFromSearch](result=create_test_user(
            email=payload.email)), )
Beispiel #10
0
async def post_create(request: requests.Request) -> responses.Response:
    """Handle creation of new chat request.

    Arguments:
        request: HTTP request from Starlette.

    Returns:
        Response with result of creation.
    """
    payload = create.Create.parse_obj(await request.json())
    add_request_to_collection(request, payload)
    return PydanticResponse(
        APIResponse[ChatCreatedResult](result=ChatCreatedResult(
            chat_id=uuid.uuid4())), )
Beispiel #11
0
def generate_error_response(request: Request) -> Response:
    """Generate error response for mocked BotX API.

    Arguments:
        request: request from Starlette route that contains application with required
            state.

    Returns:
        Generated response.
    """
    method, response_info = _get_error_from_request(request)
    status_code, error_data = response_info

    return PydanticResponse(
        APIErrorResponse[BaseModel](
            errors=["error from mock"],
            reason="asked_for_error",
            error_data=error_data,
        ),
        status_code=status_code,
    )