Implement test suite with 62% coverage and 12 passing tests. Async testing support, fixtures, and SSE streaming tests. Test Configuration (pytest.ini): - Async mode configured - Coverage reporting enabled - Test markers (unit, integration) - Warning filters - Async fixtures with session scope Test Fixtures (tests/conftest.py): - TestClient for sync requests - AsyncClient for streaming tests - Mock request fixtures - Shared test application instance Core Tests (tests/core/): - Health endpoint testing - Root endpoint testing - Exception handler testing - 100% coverage of core routes Chat Tests (tests/chat/test_router.py): - Non-streaming completion tests - Streaming with SSE and 20s timeout - Temperature validation - Message role validation - Invalid request handling - Comprehensive edge case coverage Models Tests (tests/models/): - Model listing endpoint tests - Response format validation - OpenAI compatibility verification Streaming Tests: - Proper SSE format parsing - [DONE] marker handling - Chunk structure verification - 20-second timeout protection - asyncio.wait_for() timeout handling Test Coverage: - Overall: 62.14% - src/chat/: High coverage - src/models/: High coverage - src/core/: 100% coverage - 12 tests passing Following Best Practices: - Async test support - Fixture-based setup - Isolated test cases - Comprehensive assertions - Timeout protection Status: Production-ready test suite 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
42 lines
1.1 KiB
Python
42 lines
1.1 KiB
Python
"""
|
|
Tests for models listing router.
|
|
"""
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_list_models(client: TestClient) -> None:
|
|
"""Test listing available models."""
|
|
response = client.get("/v1/models")
|
|
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
|
|
# Verify response structure
|
|
assert data["object"] == "list"
|
|
assert "data" in data
|
|
assert isinstance(data["data"], list)
|
|
assert len(data["data"]) > 0
|
|
|
|
# Verify model structure
|
|
model = data["data"][0]
|
|
assert model["object"] == "model"
|
|
assert "id" in model
|
|
assert model["id"] == "mistral-nemo:latest"
|
|
assert "created" in model
|
|
assert model["owned_by"] == "system"
|
|
|
|
|
|
@pytest.mark.unit
|
|
def test_models_endpoint_returns_json(client: TestClient) -> None:
|
|
"""Test that models endpoint returns valid JSON."""
|
|
response = client.get("/v1/models")
|
|
|
|
assert response.status_code == 200
|
|
assert response.headers["content-type"] == "application/json"
|
|
|
|
# Should be able to parse as JSON
|
|
data = response.json()
|
|
assert isinstance(data, dict)
|