Files
rar-autopass/tests/test_upload_slim.py
Claude Agent 6f6b163867 feat(web): editare celule in preview + Acasa unificata (PRD 3.6)
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>
2026-06-19 10:52:17 +00:00

101 lines
3.3 KiB
Python

"""Teste US-004 (PRD 3.6): zona de upload comprimata la o bara slim.
Cand contul are deja trimiteri, upload-ul devine o bara pe un rand (eticheta + buton
+ zona de trage). First-run pastreaza hero-ul "Primul fisier?". Drag-drop + input file
+ select-foaie (multi-sheet) raman functionale.
"""
from __future__ import annotations
import io
import json
import os
import tempfile
import pytest
from fastapi.testclient import TestClient
@pytest.fixture()
def client(monkeypatch):
tmp = tempfile.mkdtemp()
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "slim.db"))
monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "false")
from app.config import get_settings
get_settings.cache_clear()
from app.crypto import reset_cache
reset_cache()
from app.main import app
with TestClient(app) as c:
yield c
get_settings.cache_clear()
reset_cache()
def _seed_submission() -> None:
from app.db import get_connection
conn = get_connection()
try:
conn.execute(
"INSERT INTO submissions (idempotency_key, account_id, status, payload_json) "
"VALUES (?, 1, 'sent', ?)",
(f"k-{os.urandom(5).hex()}",
json.dumps({"vin": "WVWZZZ1KZAW000123", "prestatii": [{"cod_prestatie": "R-FRANE"}]})),
)
conn.commit()
finally:
conn.close()
def _multi_sheet_xlsx() -> bytes:
openpyxl = pytest.importorskip("openpyxl")
wb = openpyxl.Workbook()
ws1 = wb.active
ws1.title = "Iunie"
ws1.append(["VIN", "Nr inmatriculare", "Data prestatie", "Odometru final", "Operatie"])
ws1.append(["WVWZZZ1KZAW000123", "B001TST", "2026-06-10", "123456", "OP-1"])
ws2 = wb.create_sheet("Mai")
ws2.append(["VIN", "Nr inmatriculare", "Data prestatie", "Odometru final", "Operatie"])
ws2.append(["WVWZZZ1KZAW000999", "B009TST", "2026-05-10", "55000", "OP-1"])
buf = io.BytesIO()
wb.save(buf)
return buf.getvalue()
def test_upload_slim_pe_un_rand(client):
"""Cand contul are trimiteri, bara de upload e compacta ('Importa:'), fara hero-ul mare."""
_seed_submission()
r = client.get("/?tab=acasa")
assert r.status_code == 200
html = r.text
assert "Importa:" in html, "bara slim ('Importa:') lipseste cand contul are trimiteri"
assert "Primul fisier" not in html, "hero-ul mare nu ar trebui sa apara pentru un cont cu trimiteri"
def test_first_run_pastreaza_hero(client):
"""First-run (zero trimiteri): hero-ul 'Primul fisier?' este pastrat."""
r = client.get("/?tab=acasa")
assert r.status_code == 200
assert "Primul fisier" in r.text
def test_upload_pastreaza_drag_drop_si_input(client):
"""Input file ascuns + handler drag-drop raman functionale (JS refolosit)."""
r = client.get("/_import/reset")
assert r.status_code == 200
html = r.text
assert 'id="file-input"' in html
assert 'id="drop-zone"' in html
assert "dragover" in html and "drop" in html
def test_upload_pastreaza_select_foaie(client):
"""Cazul multi-sheet inca apare: selectorul de foaie e prezent."""
data = _multi_sheet_xlsx()
r = client.post(
"/_import/upload",
files={"file": ("multi.xlsx", io.BytesIO(data), "application/octet-stream")},
)
assert r.status_code == 200, r.text
assert 'name="sheet_name"' in r.text