mirror of
https://github.com/HKUDS/nanobot.git
synced 2026-04-23 11:25:55 +00:00
refactor(api): reduce compatibility and test noise
Make the fixed-session API surface explicit, document its usage, exclude api/ from core agent line counts, and remove implicit aiohttp pytest fixture dependencies from API tests.
This commit is contained in:
parent
d9a5080d66
commit
5e99b81c6e
@ -7,6 +7,7 @@ import json
|
|||||||
from unittest.mock import AsyncMock, MagicMock
|
from unittest.mock import AsyncMock, MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
import pytest_asyncio
|
||||||
|
|
||||||
from nanobot.api.server import (
|
from nanobot.api.server import (
|
||||||
API_CHAT_ID,
|
API_CHAT_ID,
|
||||||
@ -18,7 +19,7 @@ from nanobot.api.server import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import aiohttp # noqa: F401
|
from aiohttp.test_utils import TestClient, TestServer
|
||||||
|
|
||||||
HAS_AIOHTTP = True
|
HAS_AIOHTTP = True
|
||||||
except ImportError:
|
except ImportError:
|
||||||
@ -45,6 +46,23 @@ def app(mock_agent):
|
|||||||
return create_app(mock_agent, model_name="test-model", request_timeout=10.0)
|
return create_app(mock_agent, model_name="test-model", request_timeout=10.0)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest_asyncio.fixture
|
||||||
|
async def aiohttp_client():
|
||||||
|
clients: list[TestClient] = []
|
||||||
|
|
||||||
|
async def _make_client(app):
|
||||||
|
client = TestClient(TestServer(app))
|
||||||
|
await client.start_server()
|
||||||
|
clients.append(client)
|
||||||
|
return client
|
||||||
|
|
||||||
|
try:
|
||||||
|
yield _make_client
|
||||||
|
finally:
|
||||||
|
for client in clients:
|
||||||
|
await client.close()
|
||||||
|
|
||||||
|
|
||||||
def test_error_json() -> None:
|
def test_error_json() -> None:
|
||||||
resp = _error_json(400, "bad request")
|
resp = _error_json(400, "bad request")
|
||||||
assert resp.status == 400
|
assert resp.status == 400
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user