-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_models.py
More file actions
62 lines (41 loc) · 1.89 KB
/
test_models.py
File metadata and controls
62 lines (41 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"""Tests for the Pydantic StrictModel base + example schemas."""
from __future__ import annotations
import pytest
from pydantic import ValidationError
from src.models._base import StrictModel
from src.models.health import HealthResponse
from src.models.session import SessionCreate, SessionInfo
class _Example(StrictModel):
name: str
def test_strict_model_rejects_unknown_keys() -> None:
with pytest.raises(ValidationError, match="extra"):
_Example(name="ok", surprise="boom") # type: ignore[call-arg]
def test_strict_model_accepts_declared_keys() -> None:
obj = _Example(name="ok")
assert obj.name == "ok"
def test_health_response_status_must_be_ok() -> None:
with pytest.raises(ValidationError):
HealthResponse(status="degraded", version="0.1.0") # type: ignore[arg-type]
def test_session_create_is_empty() -> None:
SessionCreate() # constructible with no fields
def test_session_info_requires_session_id_and_created_at() -> None:
with pytest.raises(ValidationError):
SessionInfo() # type: ignore[call-arg]
def test_settings_loads_with_env_defaults(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.delenv("LLM_PROVIDER", raising=False)
monkeypatch.delenv("LLM_API_KEY", raising=False)
from src.models.config import get_settings
s = get_settings()
assert s.llm_provider == "openai"
assert s.llm_api_key == ""
assert s.llm_base_url is None
assert s.llm_model == "gpt-4o-mini"
def test_settings_reads_from_env(monkeypatch: pytest.MonkeyPatch) -> None:
monkeypatch.setenv("LLM_PROVIDER", "anthropic")
monkeypatch.setenv("LLM_API_KEY", "test-key")
monkeypatch.setenv("LLM_MODEL", "claude-haiku-4-5-20251001")
from src.models.config import get_settings
s = get_settings()
assert s.llm_provider == "anthropic"
assert s.llm_api_key == "test-key"
assert s.llm_model == "claude-haiku-4-5-20251001"