test: add comprehensive test suite with 89% coverage

- Add tests for all backend modules: config, database, models, services,
  routes, middleware, and providers
- Separate dev dependencies using dependency-groups
- Update CLAUDE.md with test commands and project structure
- Add .coverage and .pytest_cache to gitignore

88 tests covering:
- Authentication and authorization
- Model routing and key selection
- Async logging with batch processing
- All API endpoints (chat, openai, anthropic, health)
- LiteLLM wrapper (mocked external calls)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-11 19:12:57 +08:00
parent 26738973bd
commit d080e67c29
19 changed files with 1849 additions and 6 deletions

View File

@@ -0,0 +1,47 @@
"""Tests for config module."""
import pytest
from app.config import DB_PATH, HOST, PORT, LOG_BATCH_SIZE, LOG_FLUSH_INTERVAL, MODEL_PROVIDER_MAP
class TestConfig:
"""Test configuration constants."""
def test_db_path_is_pathlib_path(self):
"""Test DB_PATH is a Path object."""
from pathlib import Path
assert isinstance(DB_PATH, Path)
def test_db_path_contains_data_dir(self):
"""Test DB_PATH points to data directory."""
assert "data" in str(DB_PATH)
assert "zzrouter.db" in str(DB_PATH)
def test_host_default(self):
"""Test HOST default value."""
assert HOST == "0.0.0.0"
def test_port_default(self):
"""Test PORT default value."""
assert PORT == 8000
def test_log_batch_size_positive(self):
"""Test LOG_BATCH_SIZE is positive."""
assert LOG_BATCH_SIZE > 0
def test_log_flush_interval_positive(self):
"""Test LOG_FLUSH_INTERVAL is positive."""
assert LOG_FLUSH_INTERVAL > 0
def test_model_provider_map_contains_openai(self):
"""Test MODEL_PROVIDER_MAP contains OpenAI models."""
assert "gpt" in MODEL_PROVIDER_MAP
assert "o1" in MODEL_PROVIDER_MAP
assert "o3" in MODEL_PROVIDER_MAP
assert MODEL_PROVIDER_MAP["gpt"] == "openai"
assert MODEL_PROVIDER_MAP["o1"] == "openai"
assert MODEL_PROVIDER_MAP["o3"] == "openai"
def test_model_provider_map_contains_anthropic(self):
"""Test MODEL_PROVIDER_MAP contains Anthropic models."""
assert "claude" in MODEL_PROVIDER_MAP
assert MODEL_PROVIDER_MAP["claude"] == "anthropic"