Acasa = ecran de import (tab Import scos, ?tab=import->Acasa). Bara status compacta pe 2 randuri cu bife accesibile (glife + text) + data formatata. 'Coada'->'Trimiteri': coloane RO, stare umana, detaliu la click in panou dedicat. Mapari pe 3 sectiuni (de rezolvat / op salvate / formate coloane), Cont doar cheie+creds. Filtrare Trimiteri, corectie inline needs_data cu re-enqueue + detectie coliziune idempotency, badge contoare pe tab-uri. Helper pur partajat payload_view.py (web + GET /v1/prezentari). Backend trimitere (worker/idempotenta/mapping/schema) neatins. 483 teste. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
101 lines
3.3 KiB
Python
101 lines
3.3 KiB
Python
"""Teste US-002 (PRD 3.5): Acasa devine ecranul de import.
|
|
|
|
Upload direct pe prima pagina (importul = operatia principala); tab-ul "Import"
|
|
separat dispare, dar ?tab=import ramane valid (echivalent Acasa, fara 404).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
import tempfile
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
def _create_account_user(email: str = "dash@test.com", 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, "Service Dash", 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
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "dash.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_acasa_contine_upload(client):
|
|
"""Fragmentul /_fragments/acasa contine formularul de upload (hx-post import)."""
|
|
_create_account_user("acasaup@test.com")
|
|
_login(client, "acasaup@test.com")
|
|
|
|
resp = client.get("/_fragments/acasa")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert 'hx-post="/_import/upload"' in html, "Acasa nu contine formularul de upload"
|
|
assert 'id="import-section"' in html, "Acasa nu contine zona de import"
|
|
|
|
|
|
def test_acasa_full_load_contine_upload(client):
|
|
"""La full load pe / (tab implicit Acasa) caseta de upload e vizibila direct."""
|
|
_create_account_user("acasafull@test.com")
|
|
_login(client, "acasafull@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
assert 'hx-post="/_import/upload"' in resp.text
|
|
|
|
|
|
def test_tab_import_redirect(client):
|
|
"""?tab=import nu da 404; randeaza Acasa (echivalent), care contine upload-ul."""
|
|
_create_account_user("redir@test.com")
|
|
_login(client, "redir@test.com")
|
|
|
|
resp = client.get("/?tab=import")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
# Echivalent Acasa: contine upload-ul (import-section)
|
|
assert 'id="import-section"' in html
|
|
# Acasa e tab-ul activ (import nu mai e tab valid separat)
|
|
assert re.search(r'id="tab-acasa"[^>]*aria-selected="true"', html), \
|
|
"?tab=import ar trebui sa cada pe Acasa activ"
|
|
|
|
|
|
def test_tab_bar_fara_import(client):
|
|
"""Tab-bar-ul nu mai contine un tab 'Import' separat."""
|
|
_create_account_user("notab@test.com")
|
|
_login(client, "notab@test.com")
|
|
|
|
resp = client.get("/")
|
|
assert resp.status_code == 200
|
|
assert not re.search(r'role="tab"[^>]*>\s*Import\s*<', resp.text)
|