76 lines
2.5 KiB
Python
76 lines
2.5 KiB
Python
import pytest
|
|
|
|
from app.tarot.schema import validate_interpretation
|
|
|
|
|
|
def _valid_three():
|
|
return {
|
|
"summary": "S",
|
|
"cards": [
|
|
{"position": "과거", "card": "the-fool", "reversed": False,
|
|
"interpretation": "...", "advice": "a",
|
|
"evidence": {"card_meaning_used": "키워드", "position_logic": "p", "category_lens": "c"}},
|
|
{"position": "현재", "card": "the-lovers", "reversed": True,
|
|
"interpretation": "...", "advice": "a",
|
|
"evidence": {"card_meaning_used": "키워드", "position_logic": "p", "category_lens": "c"}},
|
|
{"position": "미래", "card": "ten-of-cups", "reversed": False,
|
|
"interpretation": "...", "advice": "a",
|
|
"evidence": {"card_meaning_used": "키워드", "position_logic": "p", "category_lens": "c"}},
|
|
],
|
|
"interactions": [{"type": "synergy", "between": ["the-fool", "ten-of-cups"], "explanation": "..."}],
|
|
"advice": "A",
|
|
"warning": None,
|
|
"confidence": "medium",
|
|
}
|
|
|
|
|
|
def test_valid_three_card_passes():
|
|
ok, msg = validate_interpretation(_valid_three(), "three_card")
|
|
assert ok, msg
|
|
|
|
|
|
def test_missing_evidence_fails():
|
|
bad = _valid_three()
|
|
del bad["cards"][0]["evidence"]
|
|
ok, msg = validate_interpretation(bad, "three_card")
|
|
assert not ok
|
|
assert "evidence" in msg
|
|
|
|
|
|
def test_empty_card_meaning_used_fails():
|
|
bad = _valid_three()
|
|
bad["cards"][0]["evidence"]["card_meaning_used"] = ""
|
|
ok, msg = validate_interpretation(bad, "three_card")
|
|
assert not ok
|
|
assert "card_meaning_used" in msg
|
|
|
|
|
|
def test_three_card_requires_interactions():
|
|
bad = _valid_three()
|
|
bad["interactions"] = []
|
|
ok, msg = validate_interpretation(bad, "three_card")
|
|
assert not ok
|
|
assert "interactions" in msg
|
|
|
|
|
|
def test_one_card_accepts_empty_interactions():
|
|
one = {
|
|
"summary": "S",
|
|
"cards": [{"position": "오늘", "card": "the-fool", "reversed": False,
|
|
"interpretation": "...", "advice": "a",
|
|
"evidence": {"card_meaning_used": "k", "position_logic": "p", "category_lens": "c"}}],
|
|
"interactions": [],
|
|
"advice": "A",
|
|
"warning": None,
|
|
"confidence": "high",
|
|
}
|
|
ok, msg = validate_interpretation(one, "one_card")
|
|
assert ok, msg
|
|
|
|
|
|
def test_invalid_confidence_fails():
|
|
bad = _valid_three()
|
|
bad["confidence"] = "very high"
|
|
ok, msg = validate_interpretation(bad, "three_card")
|
|
assert not ok
|