mirror of
https://github.com/nonebot/nonebot2.git
synced 2025-07-15 10:31:04 +00:00
🐛 fix missing endpoint name for routing
This commit is contained in:
@ -1,11 +1,56 @@
|
||||
from typing import cast
|
||||
|
||||
import pytest
|
||||
from nonebug import App
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@pytest.mark.parametrize(
|
||||
"nonebug_init",
|
||||
[{"driver": "nonebot.drivers.fastapi"}],
|
||||
[
|
||||
pytest.param({"driver": "nonebot.drivers.fastapi:Driver"}, id="fastapi"),
|
||||
pytest.param({"driver": "nonebot.drivers.quart:Driver"}, id="quart"),
|
||||
],
|
||||
indirect=True,
|
||||
)
|
||||
async def test_driver(nonebug_init):
|
||||
...
|
||||
async def test_reverse_driver(app: App):
|
||||
import nonebot
|
||||
from nonebot.drivers import (
|
||||
URL,
|
||||
Request,
|
||||
Response,
|
||||
WebSocket,
|
||||
ReverseDriver,
|
||||
HTTPServerSetup,
|
||||
WebSocketServerSetup,
|
||||
)
|
||||
|
||||
driver = cast(ReverseDriver, nonebot.get_driver())
|
||||
|
||||
async def _handle_http(request: Request) -> Response:
|
||||
assert request.content in (b"test", "test")
|
||||
return Response(200, content="test")
|
||||
|
||||
async def _handle_ws(ws: WebSocket) -> None:
|
||||
await ws.accept()
|
||||
data = await ws.receive()
|
||||
assert data == "ping"
|
||||
await ws.send("pong")
|
||||
await ws.close()
|
||||
|
||||
http_setup = HTTPServerSetup(URL("/http_test"), "POST", "http_test", _handle_http)
|
||||
driver.setup_http_server(http_setup)
|
||||
|
||||
ws_setup = WebSocketServerSetup(URL("/ws_test"), "ws_test", _handle_ws)
|
||||
driver.setup_websocket_server(ws_setup)
|
||||
|
||||
async with app.test_server() as ctx:
|
||||
client = ctx.get_client()
|
||||
response = await client.post("/http_test", data="test")
|
||||
assert response.status_code == 200
|
||||
assert response.text == "test"
|
||||
|
||||
# FIXME: https://github.com/vinissimus/async-asgi-testclient/issues/43
|
||||
# async with client.websocket_connect("/ws_test") as ws:
|
||||
# await ws.send_text("ping")
|
||||
# assert await ws.receive_text() == "pong"
|
||||
|
Reference in New Issue
Block a user