Implementeaza PRD 3.6 (US-001..007), pe canalul de import + stratul web;
worker / masina stari / idempotenta / mapare raman neatinse.
- US-003/004: tab-ul "Trimiteri" eliminat; Trimiterile devin sectiune
permanenta sub upload pe Acasa ("Trimiterile tale"); upload comprimat la
bara slim (hero pastrat la first-run); ?tab=coada si /_fragments/coada
servesc Acasa (fara fragment orfan); poll gated pe visibilityState.
- US-001: coloana noua import_rows.override_json (nullable, Fernet, Approach B)
+ _migrate defensiv; ruta v1 + alias web .../rand/{i}/editeaza aplica patch
canonic ULTIMUL in _resolve_row_for_preview si commit_import (mutatie pura,
status rederivat, fara drift). Scoping JOIN -> 404, guard committed -> 409,
semantica empty=clear, decrypt fail -> no-op.
- US-002: buton "Editeaza" pe rand; swap pe <tr> + OOB contoare (nu pe sectiune);
form propriu (confirm dezactivat la editare); refoloseste grila responsiva +
error-map din _trimitere_detaliu.html; mutual-exclusion intre randuri.
- US-005/006: "De rezolvat", "Operatii salvate" si "Formate de coloane" ca
tabele (.tablewrap); H4: comutatorul reflecta auto_send STOCAT.
- US-007: bifa "auto-send" devine comutator etichetat pe COADA ("Pune automat
in coada" / "Tine pentru verificare"), scoped pe operatie; name="auto_send"
pastrat (semantica de prezenta -> bool corect cu ambele parsere, zero backend).
Fix-uri gasite la verificarea E2E in browser (htmx 1.9.12, JS — invizibile la
TestClient): useTemplateFragments=true (raspuns <tr>+OOB era parsat in context
de tabel -> swapError + contoare pierdute); re-activarea confirm-btn dupa salvare
deferita pe tick (evita editing=true tranzitoriu); n-hint actualizat de updateN.
Teste: 523 passed. E2E browser: Acasa unificata, upload slim, editare rand
(needs_data -> ok, swap pe rand, contoare OOB), Mapari tabelar + comutator.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
129 lines
4.0 KiB
Python
129 lines
4.0 KiB
Python
"""Teste US-011 (PRD 3.5): badge cu contoare pe tab-uri (atentionari).
|
|
|
|
Badge doar cand contorul > 0; numar corect scoped pe cont; aria-label cu sens.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
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) or \
|
|
re.search(r'value="([^"]+)"\s+name="csrf_token"', resp.text)
|
|
assert m
|
|
resp = client.post("/login", data={"email": email, "parola": password, "csrf_token": m.group(1)})
|
|
assert resp.status_code == 303
|
|
|
|
|
|
def _ins(acct: int, status: str) -> None:
|
|
from app.db import get_connection
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) VALUES (?, ?, ?, ?)",
|
|
(f"k-{os.urandom(5).hex()}", acct, status, json.dumps({"vin": "X", "prestatii": []})),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _tab_link(html: str, elem_id: str) -> str:
|
|
"""Extrage tag-ul <a ...>...</a> al tab-ului cu id-ul dat."""
|
|
m = re.search(rf'<a id="{elem_id}".*?</a>', html, re.DOTALL)
|
|
assert m, f"Tab {elem_id} negasit"
|
|
return m.group(0)
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "badge.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 test_badge_mapari(client):
|
|
"""Cu operatii needs_mapping, tab-ul Mapari poarta un numar + aria-label."""
|
|
acct = _create_account_user("bm@test.com")
|
|
_ins(acct, "needs_mapping")
|
|
_ins(acct, "needs_mapping")
|
|
_login(client, "bm@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
link = _tab_link(resp.text, "tab-mapari")
|
|
assert "tab-badge" in link
|
|
assert "2" in link
|
|
assert "necesita atentie" in link # aria-label
|
|
|
|
|
|
def test_badge_trimiteri_blocate(client):
|
|
"""US-003 (3.6): cu randuri blocate, marcajul de atentie apare in heading-ul
|
|
sectiunii 'Trimiterile tale' de pe Acasa (tab-ul Trimiteri a disparut)."""
|
|
acct = _create_account_user("bt@test.com")
|
|
_ins(acct, "needs_data")
|
|
_ins(acct, "error")
|
|
_login(client, "bt@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'id="tab-coada"' not in html # tab-ul a fost eliminat
|
|
idx = html.find("Trimiterile tale")
|
|
assert idx != -1, "sectiunea Trimiteri lipseste de pe Acasa"
|
|
near = html[idx:idx + 400]
|
|
assert "tab-badge" in near
|
|
assert "2" in near
|
|
|
|
|
|
def test_badge_zero_ascuns(client):
|
|
"""Fara nimic de rezolvat, niciun badge."""
|
|
_create_account_user("bz@test.com")
|
|
_login(client, "bz@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
assert "tab-badge" not in resp.text
|
|
|
|
|
|
def test_badge_scoped_pe_cont(client):
|
|
"""Badge-ul numara doar submission-urile contului propriu."""
|
|
acct1 = _create_account_user("bs1@test.com", name="C1")
|
|
_create_account_user("bs2@test.com", name="C2")
|
|
_ins(acct1, "needs_mapping")
|
|
|
|
_login(client, "bs2@test.com")
|
|
resp = client.get("/")
|
|
assert "tab-badge" not in resp.text # contul 2 nu are nimic
|