nonebot-bison/tests/test_context.py
Azide f35c6c2fd3
♻️ 迁移到 uv 并重写 Dockerfile (#667)
Co-authored-by: BalconyJH <balconyjh@gmail.com>
Co-authored-by: suyiiyii <suyiiyii@gmail.com>
2025-01-03 17:55:06 +08:00

25 lines
960 B
Python

import httpx
from nonebug.app import App
import respx
@respx.mock
async def test_http_error(app: App):
from nonebot_bison.utils import DefaultClientManager, ProcessContext, http_client
example_route = respx.get("https://example.com")
example_route.mock(httpx.Response(403, json={"error": "gg"}))
ctx = ProcessContext(DefaultClientManager())
async with http_client() as client:
ctx._register_to_client(client)
await client.get("https://example.com")
assert ctx.gen_req_records() == [
"https://example.com Headers({'host': 'example.com', 'accept': '*/*', 'accept-encoding': 'gzip, deflate',"
" 'connection': 'keep-alive', 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36"
" (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0'}) | [403] Headers({'content-length': '"
"14', 'content-type':"
' \'application/json\'}) {"error":"gg"}'
]