61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
import pytest
|
|
from app.curator.schema import validate_response, CuratorOutput
|
|
|
|
|
|
CANDIDATE_NUMBERS = [
|
|
[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],
|
|
]
|
|
|
|
|
|
def _valid_payload():
|
|
return {
|
|
"picks": [
|
|
{"numbers": s, "risk_tag": "안정", "reason": "test"}
|
|
for s in CANDIDATE_NUMBERS[:5]
|
|
],
|
|
"narrative": {
|
|
"headline": "h", "summary_3lines": ["a", "b", "c"],
|
|
"hot_cold_comment": "hc", "warnings": "",
|
|
},
|
|
"confidence": 80,
|
|
}
|
|
|
|
|
|
def test_valid_payload_passes():
|
|
result = validate_response(_valid_payload(), CANDIDATE_NUMBERS)
|
|
assert isinstance(result, CuratorOutput)
|
|
assert len(result.picks) == 5
|
|
|
|
|
|
def test_rejects_number_out_of_candidates():
|
|
bad = _valid_payload()
|
|
bad["picks"][0]["numbers"] = [40, 41, 42, 43, 44, 45] # valid numbers but not in candidates
|
|
with pytest.raises(ValueError, match="not in candidates"):
|
|
validate_response(bad, CANDIDATE_NUMBERS)
|
|
|
|
|
|
def test_rejects_wrong_pick_count():
|
|
bad = _valid_payload()
|
|
bad["picks"] = bad["picks"][:3]
|
|
with pytest.raises(ValueError, match="exactly 5"):
|
|
validate_response(bad, CANDIDATE_NUMBERS)
|
|
|
|
|
|
def test_rejects_duplicate_numbers_within_set():
|
|
bad = _valid_payload()
|
|
bad["picks"][0]["numbers"] = [1, 1, 2, 3, 4, 5]
|
|
with pytest.raises(ValueError):
|
|
validate_response(bad, CANDIDATE_NUMBERS)
|
|
|
|
|
|
def test_rejects_invalid_risk_tag():
|
|
bad = _valid_payload()
|
|
bad["picks"][0]["risk_tag"] = "미친"
|
|
with pytest.raises(ValueError):
|
|
validate_response(bad, CANDIDATE_NUMBERS)
|