feat(T4): payload builder finalizat + snapshot test
- app/payload.py rafinat: odometruFinal/odometruInitial string (initial gol -> null), evita capcana falsy `or ""` (pastreaza "0"), normalizare vin/nrInm/coduri, tipPrestatie niciodata trimis, obs/b64Image omise cand lipsesc - tests/test_payload.py: 10 teste, inclusiv snapshot vs exemplul oficial din contract Verify: pytest 39 passed (29 + 10). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
102
tests/test_payload.py
Normal file
102
tests/test_payload.py
Normal file
@@ -0,0 +1,102 @@
|
||||
"""Teste T4 — payload builder (app.payload.build_rar_payload).
|
||||
|
||||
Snapshot fata de exemplul oficial de request din docs/api-rar-contract.md +
|
||||
invariantii din contract (status FINALIZATA, fara tipPrestatie, odometru string,
|
||||
idPrezentare null, omitere obs/b64Image, normalizare).
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.models import PrezentareIn
|
||||
from app.payload import build_rar_payload
|
||||
|
||||
|
||||
def _internal(**over) -> dict:
|
||||
data = {
|
||||
"vin": "WVWZZZ1KZAW000123",
|
||||
"nr_inmatriculare": "B999TST",
|
||||
"data_prestatie": "2026-06-15",
|
||||
"odometru_final": "123456",
|
||||
"prestatii": [{"cod_prestatie": "OE-1"}],
|
||||
}
|
||||
data.update(over)
|
||||
return PrezentareIn(**data).model_dump()
|
||||
|
||||
|
||||
def test_snapshot_exemplul_oficial_din_contract():
|
||||
"""Payload == exemplul oficial postPrezentare (request) din contract."""
|
||||
internal = {
|
||||
"vin": "XXXXXXXXXXXXXXXXX",
|
||||
"nr_inmatriculare": "B999GEN",
|
||||
"data_prestatie": "2024-12-01", # exemplul are 2024-07-25, dar acela e < min; folosim o data valida, restul identic
|
||||
"odometru_final": "9999999",
|
||||
"odometru_initial": None,
|
||||
"prestatii": [{"cod_prestatie": "OE-1"}, {"cod_prestatie": "OE-2"}],
|
||||
"sistem_reparat": "null",
|
||||
"obs": "TEST",
|
||||
"b64_image": "UklGRg==",
|
||||
}
|
||||
expected = {
|
||||
"vin": "XXXXXXXXXXXXXXXXX",
|
||||
"nrInmatriculare": "B999GEN",
|
||||
"dataPrestatie": "2024-12-01",
|
||||
"odometruFinal": "9999999",
|
||||
"odometruInitial": None,
|
||||
"prestatii": [
|
||||
{"codPrestatie": "OE-1", "idPrezentare": None},
|
||||
{"codPrestatie": "OE-2", "idPrezentare": None},
|
||||
],
|
||||
"sistemReparat": "null",
|
||||
"status": "FINALIZATA",
|
||||
"obs": "TEST",
|
||||
"b64Image": "UklGRg==",
|
||||
}
|
||||
assert build_rar_payload(PrezentareIn(**internal).model_dump()) == expected
|
||||
|
||||
|
||||
def test_status_mereu_finalizata():
|
||||
assert build_rar_payload(_internal())["status"] == "FINALIZATA"
|
||||
|
||||
|
||||
def test_nu_trimite_tipprestatie():
|
||||
assert "tipPrestatie" not in build_rar_payload(_internal())
|
||||
|
||||
|
||||
def test_odometru_final_este_string():
|
||||
p = build_rar_payload(_internal(odometru_final="55000"))
|
||||
assert p["odometruFinal"] == "55000"
|
||||
assert isinstance(p["odometruFinal"], str)
|
||||
|
||||
|
||||
def test_omite_obs_si_b64_cand_lipsesc():
|
||||
p = build_rar_payload(_internal())
|
||||
assert "obs" not in p
|
||||
assert "b64Image" not in p
|
||||
|
||||
|
||||
def test_odometru_initial_gol_devine_null():
|
||||
assert build_rar_payload(_internal(odometru_initial=""))["odometruInitial"] is None
|
||||
assert build_rar_payload(_internal())["odometruInitial"] is None
|
||||
|
||||
|
||||
def test_odometru_initial_prezent_string():
|
||||
p = build_rar_payload(_internal(prestatii=[{"cod_prestatie": "R-ODO"}], odometru_initial="100000"))
|
||||
assert p["odometruInitial"] == "100000"
|
||||
|
||||
|
||||
def test_prestatii_au_idprezentare_null():
|
||||
p = build_rar_payload(_internal(prestatii=[{"cod_prestatie": "OE-1"}, {"cod_prestatie": "OE-3"}]))
|
||||
assert p["prestatii"] == [
|
||||
{"codPrestatie": "OE-1", "idPrezentare": None},
|
||||
{"codPrestatie": "OE-3", "idPrezentare": None},
|
||||
]
|
||||
|
||||
|
||||
def test_normalizare_vin_nrinm_in_payload():
|
||||
p = build_rar_payload(_internal(vin=" wvwzzz1kzaw000123 ", nr_inmatriculare=" b999tst "))
|
||||
assert p["vin"] == "WVWZZZ1KZAW000123"
|
||||
assert p["nrInmatriculare"] == "B999TST"
|
||||
|
||||
|
||||
def test_sistem_reparat_default_null():
|
||||
assert build_rar_payload(_internal())["sistemReparat"] == "null"
|
||||
Reference in New Issue
Block a user