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>
217 lines
7.9 KiB
Python
217 lines
7.9 KiB
Python
"""Teste US-007 (PRD 3.6): bifa "auto-send" devine un comutator cu doua stari,
|
|
etichetat pe COADA (nu pe trimitere).
|
|
|
|
Framing decis la poarta autoplan (UC-A): "Pune automat in coada" / "Tine pentru
|
|
verificare". NU "Automat/Manual" (risc de send-safety peste declaratii ireversibile).
|
|
`name="auto_send"` pastrat cu semantica de prezenta (checkbox value="true"):
|
|
bifat -> auto_send True, nebifat -> absent -> False. Zero atingere backend, identic
|
|
cu ambele parsere existente (`Form(bool)` la /mapari si `bool(form.get())` la preview).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import csv
|
|
import io
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
# --- helpers comune (mirror test_mapari_tabel.py) ---
|
|
|
|
def _create_account_user(email: str, name: str = "Service", password: str = "parolasecreta10"):
|
|
from app.accounts import create_account
|
|
from app.users import create_user
|
|
from app.db import get_connection
|
|
|
|
conn = get_connection()
|
|
try:
|
|
acct_id = create_account(conn, name, active=True)
|
|
create_user(conn, acct_id, email, password)
|
|
return acct_id
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _login(client, email: str, password: str = "parolasecreta10") -> None:
|
|
resp = client.get("/login")
|
|
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text)
|
|
assert m
|
|
resp = client.post("/login", data={"email": email, "parola": password, "csrf_token": m.group(1)})
|
|
assert resp.status_code == 303
|
|
|
|
|
|
def _csrf(client) -> str:
|
|
resp = client.get("/?tab=mapari")
|
|
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text)
|
|
assert m, "csrf_token negasit"
|
|
return m.group(1)
|
|
|
|
|
|
def _seed_nomenclator(cod: str, nume: str = "Test prestatie") -> None:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"INSERT OR REPLACE INTO nomenclator_rar (cod_prestatie, nume_prestatie) VALUES (?, ?)",
|
|
(cod, nume),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _auto_send_of(acct: int, op: str) -> int | None:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
r = conn.execute(
|
|
"SELECT auto_send FROM operations_mapping WHERE account_id=? AND cod_op_service=?",
|
|
(acct, op),
|
|
).fetchone()
|
|
return None if r is None else int(r["auto_send"])
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "autosend_toggle.db"))
|
|
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "true")
|
|
from app.config import get_settings
|
|
get_settings.cache_clear()
|
|
from app.web import ratelimit
|
|
ratelimit._hits.clear()
|
|
from app.main import app
|
|
with TestClient(app, follow_redirects=False) as c:
|
|
yield c
|
|
ratelimit._hits.clear()
|
|
get_settings.cache_clear()
|
|
|
|
|
|
def _macro_html(checked: bool = True, form_id: str = "") -> str:
|
|
"""Randeaza direct macro-ul comutatorului, izolat de restul paginii."""
|
|
from app.web.routes import templates
|
|
mod = templates.env.get_template("_macros.html").make_module({})
|
|
return str(mod.autosend_toggle(form_id=form_id, checked=checked))
|
|
|
|
|
|
# --- markup / copy ---
|
|
|
|
def test_comutator_coada_prezent():
|
|
"""5.5 (supersede framing 3.6): comutator etichetat Auto/Manual, compact.
|
|
Send-safety pastrata prin tooltip/Ajutor (Manual = tine pentru verificare; nimic nu
|
|
pleaca la RAR pana confirmi). Semantica de prezenta name=auto_send nealterata."""
|
|
html = _macro_html()
|
|
assert "name=\"auto_send\"" in html and 'value="true"' in html
|
|
assert "Auto" in html and "Manual" in html, "ambele stari etichetate"
|
|
assert "verificare" in html, "sensul de verificare manuala trebuie pastrat (tooltip/ajutor)"
|
|
assert "trimite" not in html.lower(), "fara cuvantul 'trimite' izolat in eticheta"
|
|
assert "auto-send" not in html, "jargonul 'auto-send' trebuie inlocuit"
|
|
|
|
|
|
def test_eticheta_scoped_pe_operatie():
|
|
"""Microcopy scoped pe operatie (NU global)."""
|
|
html = _macro_html()
|
|
assert "aceasta operatie" in html
|
|
|
|
|
|
def test_default_pune_automat():
|
|
"""Default = "Pune automat in coada" (mirror la checkbox-ul `checked` de azi)."""
|
|
html_default = _macro_html(checked=True)
|
|
assert "checked" in html_default
|
|
html_off = _macro_html(checked=False)
|
|
assert "checked" not in html_off, "starea stocata False nu trebuie bifata (H4)"
|
|
|
|
|
|
# --- comportament (zero atingere backend) ---
|
|
|
|
def test_pune_automat_mapeaza_auto_send_true(client):
|
|
"""Bifat -> auto_send=true trimis -> stocat True (identic cu azi)."""
|
|
acct = _create_account_user("pa@test.com")
|
|
_seed_nomenclator("R-FRANE")
|
|
_login(client, "pa@test.com")
|
|
csrf = _csrf(client)
|
|
resp = client.post("/mapari", data={
|
|
"cod_op_service": "OP-A", "cod_prestatie": "R-FRANE",
|
|
"auto_send": "true", "csrf_token": csrf,
|
|
})
|
|
assert resp.status_code == 200
|
|
assert _auto_send_of(acct, "OP-A") == 1
|
|
|
|
|
|
def test_tine_pentru_verificare_mapeaza_auto_send_false(client):
|
|
"""Nebifat -> camp absent -> stocat False (semantica de prezenta a checkbox-ului)."""
|
|
acct = _create_account_user("tv@test.com")
|
|
_seed_nomenclator("R-FRANE")
|
|
_login(client, "tv@test.com")
|
|
csrf = _csrf(client)
|
|
# "Tine pentru verificare" = comutatorul nebifat -> name=auto_send NU se trimite
|
|
resp = client.post("/mapari", data={
|
|
"cod_op_service": "OP-B", "cod_prestatie": "R-FRANE", "csrf_token": csrf,
|
|
})
|
|
assert resp.status_code == 200
|
|
assert _auto_send_of(acct, "OP-B") == 0
|
|
|
|
|
|
# --- prezent in AMBELE locuri (mapari tab + panou preview) ---
|
|
|
|
def test_comutator_in_tab_mapari(client):
|
|
"""Tabul Mapari (de-rezolvat) foloseste comutatorul de coada, nu jargonul vechi."""
|
|
from app.db import get_connection
|
|
import json
|
|
acct = _create_account_user("tm@test.com")
|
|
_seed_nomenclator("R-FRANE")
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) "
|
|
"VALUES (?, ?, 'needs_mapping', ?)",
|
|
("k-tm", acct, json.dumps({"prestatii": [{"cod_op_service": "OP-NM", "denumire": "x"}]})),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
_login(client, "tm@test.com")
|
|
resp = client.get("/?tab=mapari")
|
|
assert resp.status_code == 200
|
|
# 5.5: comutatorul compact Auto/Manual e prezent in tabul Mapari
|
|
assert 'name="auto_send"' in resp.text
|
|
assert "Manual" in resp.text and "Auto" in resp.text
|
|
|
|
|
|
def test_comutator_in_panou_preview(client):
|
|
"""Panoul de mapare din preview are si el comutatorul + caption (azi lipsea caption)."""
|
|
_create_account_user("pp@test.com")
|
|
_seed_nomenclator("R-FRANE")
|
|
_login(client, "pp@test.com")
|
|
csrf = _csrf(client)
|
|
|
|
buf = io.StringIO()
|
|
w = csv.DictWriter(buf, fieldnames=["VIN", "Nr", "Data", "Odo", "Operatie"], delimiter=";")
|
|
w.writeheader()
|
|
w.writerow({"VIN": "WVWZZZ1KZAW000123", "Nr": "B001TST",
|
|
"Data": "15.06.2026", "Odo": "123456", "Operatie": "OP-NEMAPAT"})
|
|
data = buf.getvalue().encode("utf-8")
|
|
|
|
r = client.post("/_import/upload", files={"file": ("t.csv", data, "text/csv")},
|
|
data={"csrf_token": csrf})
|
|
assert r.status_code == 200
|
|
m = re.search(r"/_import/(\d+)/mapare-coloane", r.text)
|
|
assert m
|
|
import_id = int(m.group(1))
|
|
r = client.post(f"/_import/{import_id}/mapare-coloane", data={
|
|
"colname": ["VIN", "Nr", "Data", "Odo", "Operatie"],
|
|
"canon": ["vin", "nr_inmatriculare", "data_prestatie", "odometru_final", "operatie"],
|
|
"format_data": "DD.MM.YYYY", "csrf_token": csrf,
|
|
})
|
|
assert r.status_code == 200
|
|
assert "OP-NEMAPAT" in r.text, "operatia nemapata trebuie sa apara in panoul de mapare"
|
|
# 5.5: comutatorul compact Auto/Manual e prezent si in panoul de mapare din preview
|
|
assert 'name="auto_send"' in r.text
|
|
assert "Manual" in r.text and "Auto" in r.text
|