feat(errors): erori pe 3 niveluri (problema+cauza+fix) pe API si UI (PRD 5.4)
Catalog central pur app/errors.py ca sursa unica cod->{problema,fix},
consumat de API+UI+worker. Aditiv (field/message pastrate la octet) +
rar_error stocat superset. Scope: fluxul de declarare; login/signup/CSRF
neatinse. labels.parse_erori degradeaza gratios; UI progresiv AA light+dark.
631 teste.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
77
tests/test_errors.py
Normal file
77
tests/test_errors.py
Normal file
@@ -0,0 +1,77 @@
|
||||
"""Teste pentru app/errors.py — catalog central de erori (US-001 / PRD 5.4).
|
||||
|
||||
Urmeaza TDD: testele sunt scrise INAINTE de implementare.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
|
||||
from app.errors import CATALOG, eroare
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# test_catalog_complet
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_catalog_complet():
|
||||
"""Fiecare intrare din CATALOG are 'problema' si 'fix' ne-goale."""
|
||||
assert len(CATALOG) >= 24, "CATALOG trebuie sa contina cel putin 24 de coduri"
|
||||
for cod, entry in CATALOG.items():
|
||||
assert "problema" in entry, f"Lipseste 'problema' pentru codul {cod!r}"
|
||||
assert "fix" in entry, f"Lipseste 'fix' pentru codul {cod!r}"
|
||||
assert isinstance(entry["problema"], str) and entry["problema"].strip(), (
|
||||
f"'problema' goala pentru codul {cod!r}"
|
||||
)
|
||||
assert isinstance(entry["fix"], str) and entry["fix"].strip(), (
|
||||
f"'fix' gol pentru codul {cod!r}"
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# test_eroare_construieste_3niveluri
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_eroare_construieste_3niveluri():
|
||||
"""eroare() intoarce dict cu exact cheile asteptate si valorile corecte."""
|
||||
rezultat = eroare("VIN_FORMAT", field="vin", cauza="VIN-ul are 15 caractere")
|
||||
|
||||
chei_asteptate = {"field", "cod", "problema", "cauza", "fix", "message"}
|
||||
assert set(rezultat.keys()) == chei_asteptate, (
|
||||
f"Cheile obtinute: {set(rezultat.keys())} — asteptate: {chei_asteptate}"
|
||||
)
|
||||
|
||||
assert rezultat["cod"] == "VIN_FORMAT"
|
||||
assert rezultat["field"] == "vin"
|
||||
assert rezultat["cauza"] == "VIN-ul are 15 caractere"
|
||||
assert rezultat["problema"] == CATALOG["VIN_FORMAT"]["problema"]
|
||||
assert rezultat["fix"] == CATALOG["VIN_FORMAT"]["fix"]
|
||||
# message == cauza cand cauza este dat
|
||||
assert rezultat["message"] == "VIN-ul are 15 caractere"
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# test_message_back_compat
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_message_back_compat():
|
||||
"""message == cauza cand cauza e dat; message == problema cand cauza lipseste."""
|
||||
# Cu cauza
|
||||
cu_cauza = eroare("DATA_FORMAT", cauza="data_primita=31/06/2026")
|
||||
assert cu_cauza["message"] == "data_primita=31/06/2026"
|
||||
|
||||
# Fara cauza
|
||||
fara_cauza = eroare("DATA_FORMAT")
|
||||
assert fara_cauza["message"] == CATALOG["DATA_FORMAT"]["problema"]
|
||||
# cauza din dict e None sau egala cu problema
|
||||
assert fara_cauza["cauza"] == CATALOG["DATA_FORMAT"]["problema"]
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# test_cod_necunoscut_ridica
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
def test_cod_necunoscut_ridica():
|
||||
"""eroare() pe cod absent din CATALOG ridica KeyError."""
|
||||
with pytest.raises(KeyError):
|
||||
eroare("INEXISTENT")
|
||||
Reference in New Issue
Block a user