Skip to content

Commit

Permalink
Reverse sync request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Kudinov committed Jun 4, 2024
1 parent b4c0459 commit 4a7f0b6
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 168 deletions.
27 changes: 0 additions & 27 deletions app/api/endpoints/botx.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,15 @@
from http import HTTPStatus

from fastapi import APIRouter, Request
from fastapi.encoders import jsonable_encoder
from fastapi.responses import JSONResponse
from pybotx import (
Bot,
UnknownBotAccountError,
build_bot_disabled_response,
build_command_accepted_response,
)
from pybotx_smartapp_rpc import SmartApp
from pybotx_smartapp_rpc.models.request import RPCRequest

from app.api.dependencies.bot import bot_dependency
from app.schemas.sync_request import (
SyncRequest,
transfrorm_sync_request_to_smartapp_event,
)
from app.logger import logger

router = APIRouter()
Expand Down Expand Up @@ -66,23 +59,3 @@ async def callback_handler(request: Request, bot: Bot = bot_dependency) -> JSONR
build_command_accepted_response(),
status_code=HTTPStatus.ACCEPTED,
)


@router.post("/smartapps/request")
async def sync_request_handler(
request: SyncRequest, bot: Bot = bot_dependency
) -> JSONResponse:
smartapp_event = transfrorm_sync_request_to_smartapp_event(request, bot)
smartapp = SmartApp(
bot, smartapp_event.bot.id, smartapp_event.chat.id, smartapp_event
)
rpc_request = RPCRequest(**smartapp_event.data)

rpc_response = (
await bot.state.smartapp_rpc._router.perform_rpc_request( # noqa: WPS437
smartapp, rpc_request
)
)

json = jsonable_encoder(rpc_response.jsonable_dict())
return JSONResponse(json)
8 changes: 4 additions & 4 deletions app/bot/middlewares/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
from pybotx_smartapp_rpc import RPCArgsBaseModel, SmartApp
from pybotx_smartapp_rpc.typing import Handler, RPCResponse

from app.services.answers import build_incoming_smartapp_event_text


async def debug_middleware(
smartapp: SmartApp, rpc_arguments: RPCArgsBaseModel, call_next: Handler
) -> RPCResponse:
"""TODO: uncomment code after pybotx implements sync requests.
await smartapp.bot.answer_message(
build_incoming_smartapp_event_text(smartapp.event.raw_command)
build_incoming_smartapp_event_text(smartapp.event.raw_command)
)
"""

return await call_next(smartapp, rpc_arguments)
5 changes: 0 additions & 5 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,3 @@ def get_application() -> FastAPI:


app = get_application()


if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host='0.0.0.0', port=4004, reload=True, debug=True, workers=3)
132 changes: 0 additions & 132 deletions app/schemas/sync_request.py

This file was deleted.

0 comments on commit 4a7f0b6

Please sign in to comment.