50 lines
1.4 KiB
Python
50 lines
1.4 KiB
Python
"""Quick schema validation tests — run with `pytest tests/`."""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from cloak.schemas import SearchRequest, SearchResponse, EngineStats, SearchResult
|
|
|
|
|
|
def test_search_request_minimal():
|
|
req = SearchRequest(queries=["BNR confiscare"])
|
|
assert req.queries == ["BNR confiscare"]
|
|
assert req.engines == ["google", "bing", "ddg"]
|
|
assert req.max_results_per_engine == 10
|
|
|
|
|
|
def test_search_request_rejects_unknown_engine():
|
|
with pytest.raises(ValidationError):
|
|
SearchRequest(queries=["x"], engines=["yahoo"])
|
|
|
|
|
|
def test_search_request_rejects_empty_queries():
|
|
with pytest.raises(ValidationError):
|
|
SearchRequest(queries=[])
|
|
|
|
|
|
def test_search_response_round_trip():
|
|
resp = SearchResponse(
|
|
results=[
|
|
SearchResult(
|
|
url="https://example.com",
|
|
title="Example",
|
|
snippet="...",
|
|
engine="google",
|
|
query="test",
|
|
rank=1,
|
|
),
|
|
],
|
|
stats=[
|
|
EngineStats(
|
|
engine="google", query="test",
|
|
results_count=1, elapsed_ms=2000,
|
|
),
|
|
],
|
|
total_elapsed_ms=2050,
|
|
)
|
|
j = resp.model_dump_json()
|
|
parsed = SearchResponse.model_validate_json(j)
|
|
assert len(parsed.results) == 1
|
|
assert parsed.stats[0].engine == "google"
|