Buckets:
AnonymousSpottedToad/candidate_bucket / codebase /python /GRID-INTELLIGENCE_GRID /tests /unit /test_inference_router.py
| """ | |
| Unit tests for the Mothership inference router. | |
| Covers: models listing, async inference queuing, task status lookup. | |
| """ | |
| from __future__ import annotations | |
| import pytest | |
| import pytest_asyncio | |
| from httpx import ASGITransport, AsyncClient | |
| def anyio_backend(): | |
| return "asyncio" | |
| async def client(): | |
| from application.mothership.main import create_app | |
| app = create_app() | |
| transport = ASGITransport(app=app) | |
| async with AsyncClient(transport=transport, base_url="http://testserver") as ac: | |
| yield ac | |
| async def auth_headers(client: AsyncClient) -> dict[str, str]: | |
| resp = await client.post("/api/v1/auth/login", json={"username": "operator", "password": "operator"}) | |
| if resp.status_code == 200: | |
| data = resp.json() | |
| token = data.get("data", {}).get("access_token", data.get("access_token", data.get("token", "dev"))) | |
| return {"Authorization": f"Bearer {token}"} | |
| return {"Authorization": "Bearer dev-test-token"} | |
| class TestInferenceModels: | |
| async def test_list_models_returns_list(self, client, auth_headers): | |
| resp = await client.get("/api/v1/inference/models", headers=auth_headers) | |
| assert resp.status_code == 200 | |
| data = resp.json() | |
| assert "models" in data | |
| assert isinstance(data["models"], list) | |
| assert "default" in data | |
| async def test_list_models_has_default(self, client, auth_headers): | |
| resp = await client.get("/api/v1/inference/models", headers=auth_headers) | |
| data = resp.json() | |
| assert data["default"] in data["models"] | |
| class TestInferenceAsync: | |
| async def test_async_inference_returns_task_id(self, client, auth_headers): | |
| resp = await client.post( | |
| "/api/v1/inference/async", | |
| json={"prompt": "Hello world"}, | |
| headers=auth_headers, | |
| ) | |
| # May return 200 (queued) or 503 (service unavailable) | |
| if resp.status_code == 200: | |
| data = resp.json() | |
| assert "task_id" in data | |
| assert data["status"] == "queued" | |
| async def test_status_unknown_task_returns_404(self, client, auth_headers): | |
| resp = await client.get( | |
| "/api/v1/inference/status/nonexistent_task_id", | |
| headers=auth_headers, | |
| ) | |
| assert resp.status_code in (404, 500) | |
Xet Storage Details
- Size:
- 2.51 kB
- Xet hash:
- 192b41756087f9f3039fa887ba67015dcbf6940216389cd1191d4c3037b4e259
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.