"""Teste US-003 — pasul „Potriveste coloanele" arata antet + prima inregistrare. Acceptance criteria: - Deasupra/langa randurile de mapare, un mic tabel orizontal: cap de tabel = numele coloanelor din fisier, rand = valorile primei inregistrari (truncate; `title` pe valoarea integrala). - Foloseste .tablewrap pentru scroll orizontal pe mobil. - Fiecare coloana din cap ramane asociata vizual cu select-ul ei de mapare. - Fisier fara randuri de date -> doar capul de tabel + mesaj explicit „antet fara randuri de date" (D#11) + butonul „Continua" dezactivat. """ from __future__ import annotations import io import os import tempfile import pytest @pytest.fixture() def client(monkeypatch): tmp = tempfile.mkdtemp() monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "t.db")) monkeypatch.setenv("AUTOPASS_WEB_AUTH_REQUIRED", "false") from app.config import get_settings get_settings.cache_clear() from app.main import app from fastapi.testclient import TestClient with TestClient(app) as c: yield c get_settings.cache_clear() def _make_xlsx_bytes(rows: list[dict]) -> bytes: """Construieste un xlsx minimal cu openpyxl.""" openpyxl = pytest.importorskip("openpyxl") wb = openpyxl.Workbook() ws = wb.active if not rows: return b"" headers = list(rows[0].keys()) ws.append(headers) for row in rows: ws.append([row.get(h) for h in headers]) buf = io.BytesIO() wb.save(buf) return buf.getvalue() def _make_xlsx_only_header(headers: list[str]) -> bytes: """Construieste un xlsx cu doar antet (fara randuri de date).""" openpyxl = pytest.importorskip("openpyxl") wb = openpyxl.Workbook() ws = wb.active ws.append(headers) buf = io.BytesIO() wb.save(buf) return buf.getvalue() _COLOANE = ["VIN", "Nr inmatriculare", "Data prestatie", "Odometru final", "Operatie"] _SAMPLE_ROWS = [ { "VIN": "WVWZZZ1KZAW000123", "Nr inmatriculare": "B001TST", "Data prestatie": "15.06.2026", "Odometru final": "123456", "Operatie": "Revizie", }, { "VIN": "WVWZZZ1KZAW000456", "Nr inmatriculare": "B002TST", "Data prestatie": "16.06.2026", "Odometru final": "200000", "Operatie": "Revizie", }, ] def _upload_csv_and_get_mapare(client, rows=None, headers=None) -> tuple[int, str]: """Incarca un xlsx si intoarce (import_id, html_text) din pasul de mapare coloane.""" if headers is not None: # Fisier cu doar antet xlsx = _make_xlsx_only_header(headers) else: xlsx = _make_xlsx_bytes(rows or _SAMPLE_ROWS) r = client.post( "/_import/upload", files={"file": ("test.xlsx", xlsx, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")}, ) return r.status_code, r.text # --------------------------------------------------------------------------- # # test_mapcoloane_arata_cap_tabel_coloane # # --------------------------------------------------------------------------- # def test_mapcoloane_arata_cap_tabel_coloane(client): """Pasul de mapare coloane afiseaza un tabel orizontal cu antetul fisierului. Fiecare coloana din fisier trebuie sa apara ca