Aduce toate suprafetele dashboard-ului la grila tabelului Trimiteri, muta
navigarea intr-un meniu de cont (hamburger) si da panoului admin actiuni
reale de ciclu de viata. 9 stories, 3 valuri. UI pur (reskin + reasezare)
cu O SINGURA exceptie backend: modelul de stare a contului.
- US-001 sectiunea "Ajutor" eliminata din Acasa (wayfinding redundant).
- US-002 Nomenclator la grila standard (_submissions.html ca referinta).
- US-003 macro autosend compact (Manual<->Auto). Semantica de PREZENTA
`auto_send` (bifat->true, absent->false) NEALTERATA — compatibil cu ambele
parsere (Form(bool) la /mapari, bool(form.get()) la import). Zero backend.
- US-004 accounts.status (pending/active/blocked/archived/deleted), migrare
defensiva idempotenta derivata din `active`, gate worker claim_one pe
status='active' (echivalenta active=1 <=> status='active' pastrata).
- US-005 tabel Mapari compact + panou Ajutor (<details>, proza o singura data),
coloana "In coada".
- US-006 meniu hamburger dropdown (Cont/Integrare/Nomenclator/Admin/logout) +
context is_authenticated/is_admin/csrf_token defensiv in base.html.
- US-007 tab-bar redus la Acasa+Mapari; rutele /_fragments/{cont,integrare,
nomenclator} + deep-link ?tab= raman valide.
- US-008 rute admin block/archive/delete + bulk pe lista account_id,
require_admin + CSRF + PRG, dev id=1 sarit in bulk.
- US-009 admin UI: selectie bife + master + bara bulk + kebab per-rand,
grupare pe stare (bloc nou blocate/arhivate), nota "cont dev implicit" scoasa.
Stergere = SOFT: tombstone (status='deleted'), dar PII purjata IMEDIAT
(rar_creds_enc + chei API revocate + CUI eliberat pentru re-inregistrare),
GDPR/L.142.
VERIFY: 671 teste pass (+40). E2E browser (Playwright) a prins 2 bug-uri
invizibile la TestClient: bara bulk cu display:flex inline invingea [hidden]
(mutat in CSS .bulk-bar[hidden]); conturi arhivate cadeau sub "in asteptare"
(grupare pe status). /code-review high a prins 2 bug-uri reale: soft delete
pastra creds RAR + CUI la nesfarsit fara purjare accounts (GDPR neonorat);
apostrof in numele firmei rupea confirm() inline din kebab — ambele reparate,
plus cleanup boilerplate rute (_lifecycle_route).
Backend trimitere (worker masina stari/idempotenta/mapping) neatins, cu
exceptia gate-ului de cont. Design: docs/design/5.5-uniformizare-ui.md.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
185 lines
7.4 KiB
Python
185 lines
7.4 KiB
Python
"""
|
|
Teste pentru app/web/labels.py — modul de etichete umane (US-001, PRD 3.4).
|
|
|
|
Ordinea: RED (scrise inainte de implementare), apoi GREEN dupa creare labels.py.
|
|
"""
|
|
|
|
import re
|
|
import pytest
|
|
from pathlib import Path
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Utilitara: extrage starile din CHECK constraint in schema.sql
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def _starile_din_schema() -> list[str]:
|
|
"""
|
|
Parseaza `app/schema.sql` si returneaza lista starilor din CHECK constraint
|
|
al coloanei `status` din tabela `submissions`.
|
|
|
|
Linia relevanta (schema.sql, tabela submissions):
|
|
CHECK (status IN ('queued','sending','sent','needs_mapping','needs_data','error'))
|
|
|
|
Testul devine automat RED daca cineva adauga o stare noua in schema
|
|
fara s-o mapeze in labels.py.
|
|
"""
|
|
schema_path = Path(__file__).parent.parent / "app" / "schema.sql"
|
|
sql = schema_path.read_text(encoding="utf-8")
|
|
|
|
# Cauta blocul CHECK aferent coloanei status din CREATE TABLE submissions.
|
|
# Nota (5.5): de cand exista si `accounts.status` cu propriul CHECK, ancoram pe blocul
|
|
# tabelei submissions (`CREATE TABLE ... submissions`) ca sa nu prindem starile de cont.
|
|
tbl = re.search(
|
|
r"CREATE TABLE[^;]*?submissions\b(.*?);", sql, re.IGNORECASE | re.DOTALL
|
|
)
|
|
assert tbl, "Nu am gasit CREATE TABLE submissions in schema.sql — schema s-a schimbat?"
|
|
match = re.search(
|
|
r"CHECK\s*\(\s*status\s+IN\s*\(([^)]+)\)\s*\)",
|
|
tbl.group(1),
|
|
)
|
|
assert match, "Nu am gasit CHECK (status IN (...)) in submissions — schema s-a schimbat?"
|
|
|
|
raw = match.group(1)
|
|
# Extrage valorile dintre ghilimele simple
|
|
stari = re.findall(r"'([^']+)'", raw)
|
|
assert stari, "Lista de stari din CHECK este goala — ceva s-a stricat la parsare."
|
|
return stari
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Import modulul de etichete (va esua la RED, inainte de implementare)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
from app.web.labels import ( # noqa: E402
|
|
eticheta_stare,
|
|
eticheta_worker,
|
|
eticheta_rar,
|
|
format_data_rar,
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Teste worker
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_eticheta_worker_viu():
|
|
text, subtext, css_class = eticheta_worker(viu=True)
|
|
assert "Trimitere automata" in text, (
|
|
f"Textul pentru worker viu trebuie sa contina 'Trimitere automata', got: {text!r}"
|
|
)
|
|
assert "activa" in text.lower() or "activa" in subtext.lower(), (
|
|
f"Starea 'activa' trebuie sa apara in text sau subtext, got: text={text!r}, subtext={subtext!r}"
|
|
)
|
|
# Nu trebuie sa afiseze cuvintele tehnice brute
|
|
assert "viu" not in text.lower(), f"Textul nu trebuie sa contina 'viu': {text!r}"
|
|
# Clasa CSS trebuie sa fie definita (non-vida)
|
|
assert css_class, "css_class nu trebuie sa fie vida pentru worker viu"
|
|
|
|
|
|
def test_eticheta_worker_mort():
|
|
text, subtext, css_class = eticheta_worker(viu=False)
|
|
assert "Trimitere automata" in text, (
|
|
f"Textul pentru worker mort trebuie sa contina 'Trimitere automata', got: {text!r}"
|
|
)
|
|
assert "oprita" in text.lower() or "oprita" in subtext.lower(), (
|
|
f"Starea 'oprita' trebuie sa apara in text sau subtext, got: text={text!r}, subtext={subtext!r}"
|
|
)
|
|
assert "mort" not in text.lower(), f"Textul nu trebuie sa contina 'mort': {text!r}"
|
|
assert css_class, "css_class nu trebuie sa fie vida pentru worker mort"
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Teste eticheta_rar
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_eticheta_rar_ok():
|
|
text, subtext, css_class = eticheta_rar(stare="ok")
|
|
assert "Legatura cu RAR" in text, f"got: {text!r}"
|
|
assert "functionala" in text.lower() or "functionala" in subtext.lower()
|
|
assert css_class
|
|
|
|
|
|
def test_eticheta_rar_indisponibil():
|
|
text, subtext, css_class = eticheta_rar(stare="indisponibil")
|
|
assert "Legatura cu RAR" in text, f"got: {text!r}"
|
|
assert "indisponibila" in text.lower() or "indisponibila" in subtext.lower()
|
|
assert css_class
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Test eticheta_stare pentru fiecare stare de submission
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_eticheta_stare_submission():
|
|
"""Verifica textele umane concrete pentru fiecare stare cunoscuta."""
|
|
cazuri = {
|
|
"queued": ("In asteptare", "s-queued"),
|
|
"sent": ("Declarate la RAR", "s-sent"),
|
|
"sending": ("Se trimite", "s-sending"),
|
|
"needs_mapping": ("Lipseste codul", "s-needs_mapping"),
|
|
"needs_data": ("Date incomplete", "s-needs_data"),
|
|
"error": ("Eroare", "s-error"),
|
|
}
|
|
for status, (fragment_text, clasa) in cazuri.items():
|
|
text, subtext, css_class = eticheta_stare(status)
|
|
assert fragment_text.lower() in text.lower(), (
|
|
f"Status {status!r}: asteptam '{fragment_text}' in text, got {text!r}"
|
|
)
|
|
assert css_class == clasa, (
|
|
f"Status {status!r}: asteptam css_class={clasa!r}, got {css_class!r}"
|
|
)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Test parametrizat: TOATE starile din schema au eticheta (anti-drift)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
_STARI_SCHEMA = _starile_din_schema()
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Test format_data_rar (US-001, PRD 3.5)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
def test_format_data_rar():
|
|
"""`2026-06-18T14:30:22` -> `18.06.2026 14:30:22`."""
|
|
assert format_data_rar("2026-06-18T14:30:22") == "18.06.2026 14:30:22"
|
|
|
|
|
|
def test_format_data_rar_cu_timezone():
|
|
"""Timezone si microsecunde nu strica formatarea; fractiunile cad."""
|
|
assert format_data_rar("2026-06-18T14:30:22.123456+00:00") == "18.06.2026 14:30:22"
|
|
assert format_data_rar("2026-06-18T14:30:22Z") == "18.06.2026 14:30:22"
|
|
|
|
|
|
def test_format_data_rar_lipsa():
|
|
"""Valoare lipsa -> em-dash, nu exceptie."""
|
|
assert format_data_rar(None) == "—"
|
|
assert format_data_rar("") == "—"
|
|
assert format_data_rar(" ") == "—"
|
|
|
|
|
|
def test_format_data_rar_invalid():
|
|
"""Format invalid -> fallback grijuliu (intoarce brutul, nu arunca)."""
|
|
# Nu trebuie sa arunce
|
|
assert format_data_rar("nu-e-data") == "nu-e-data"
|
|
assert format_data_rar(12345) == "12345"
|
|
|
|
|
|
@pytest.mark.parametrize("status", _STARI_SCHEMA)
|
|
def test_toate_starile_au_eticheta(status: str):
|
|
"""
|
|
Fiecare stare din CHECK constraint (schema.sql) trebuie sa aiba o eticheta
|
|
non-vida si o clasa CSS non-vida in labels.py.
|
|
|
|
Daca cineva adauga o stare noua in schema fara s-o mapeze, acest test devine RED.
|
|
"""
|
|
text, subtext, css_class = eticheta_stare(status)
|
|
assert text, f"Status {status!r}: textul etichetei este vid."
|
|
assert css_class, f"Status {status!r}: clasa CSS este vida."
|
|
# Textul nu trebuie sa fie chiar statusul tehnic brut (ex. "queued" afisat ca atare)
|
|
assert text.lower() != status.lower(), (
|
|
f"Status {status!r}: eticheta umana este identica cu statusul tehnic — nu e o eticheta umana."
|
|
)
|