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>
130 lines
4.4 KiB
Python
130 lines
4.4 KiB
Python
"""Teste US-001 (PRD 3.5): bara de status compacta cu bife accesibile + data formatata.
|
|
|
|
Bifa = glifa distincta (✓ / ✗) + text, NU doar culoare (daltonism, design review).
|
|
Verde/✓ cand worker viu + RAR ok; rosu/✗ cand oprit/indisponibil.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
import re
|
|
import tempfile
|
|
from datetime import datetime, timezone
|
|
|
|
import pytest
|
|
from starlette.testclient import TestClient
|
|
|
|
|
|
def _create_account_user(email: str, 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 Test Bife", active=True)
|
|
user_id = create_user(conn, acct_id, email, password)
|
|
return acct_id, user_id
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
def _login(client, email: str, password: str) -> None:
|
|
resp = client.get("/login")
|
|
assert resp.status_code == 200
|
|
m = re.search(r'name="csrf_token"\s+value="([^"]+)"', resp.text)
|
|
if not m:
|
|
m = re.search(r'value="([^"]+)"\s+name="csrf_token"', resp.text)
|
|
assert m, "csrf_token negasit pe /login"
|
|
resp = client.post("/login", data={"email": email, "parola": password, "csrf_token": m.group(1)})
|
|
assert resp.status_code == 303, f"Login esuat: {resp.status_code} {resp.text[:200]}"
|
|
|
|
|
|
def _set_heartbeat(last_beat: str | None, last_rar_login_ok: str | None) -> None:
|
|
from app.db import get_connection
|
|
|
|
conn = get_connection()
|
|
try:
|
|
conn.execute(
|
|
"UPDATE worker_heartbeat SET last_beat=?, last_rar_login_ok=? WHERE id=1",
|
|
(last_beat, last_rar_login_ok),
|
|
)
|
|
conn.commit()
|
|
finally:
|
|
conn.close()
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(monkeypatch):
|
|
tmp = tempfile.mkdtemp()
|
|
monkeypatch.setenv("AUTOPASS_DB_PATH", os.path.join(tmp, "bife_test.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_status_are_bife_verzi_cand_totul_ok(client):
|
|
"""Worker viu + RAR login recent -> bifa verde ✓ pentru ambele stari binare."""
|
|
_create_account_user("bifeok@test.com")
|
|
_login(client, "bifeok@test.com", "parolasecreta10")
|
|
|
|
now = datetime.now(timezone.utc).isoformat()
|
|
_set_heartbeat(last_beat=now, last_rar_login_ok=now)
|
|
|
|
resp = client.get("/_fragments/status")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
# Glifa de OK prezenta (accesibilitate: nu doar culoare)
|
|
assert "✓" in html, f"Lipseste glifa ✓ cand totul e ok. HTML: {html[:600]}"
|
|
# Texte umane de OK
|
|
assert "activa" in html.lower()
|
|
assert "functionala" in html.lower()
|
|
|
|
|
|
def test_status_are_bife_rosii_cand_worker_oprit(client):
|
|
"""Fara heartbeat -> worker oprit -> bifa rosie ✗ + text 'oprita'."""
|
|
_create_account_user("biferosu@test.com")
|
|
_login(client, "biferosu@test.com", "parolasecreta10")
|
|
|
|
_set_heartbeat(last_beat=None, last_rar_login_ok=None)
|
|
|
|
resp = client.get("/_fragments/status")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
assert "✗" in html, f"Lipseste glifa ✗ cand worker oprit. HTML: {html[:600]}"
|
|
assert "oprita" in html.lower()
|
|
|
|
|
|
def test_status_data_formatata_romaneste(client):
|
|
"""Ultima autentificare RAR apare ca dd.mm.yyyy hh24:mi:ss."""
|
|
_create_account_user("bifedata@test.com")
|
|
_login(client, "bifedata@test.com", "parolasecreta10")
|
|
|
|
now = datetime.now(timezone.utc).isoformat()
|
|
_set_heartbeat(last_beat=now, last_rar_login_ok="2026-06-18T14:30:22")
|
|
|
|
resp = client.get("/_fragments/status")
|
|
assert resp.status_code == 200
|
|
assert "18.06.2026 14:30:22" in resp.text, (
|
|
f"Data nu e formatata romaneste. HTML: {resp.text[:800]}"
|
|
)
|
|
|
|
|
|
def test_status_fara_fonturi_minuscule(client):
|
|
"""Niciun text din bara nu mai foloseste font-size sub 13px (US-001 AC)."""
|
|
_create_account_user("bifefont@test.com")
|
|
_login(client, "bifefont@test.com", "parolasecreta10")
|
|
|
|
resp = client.get("/_fragments/status")
|
|
assert resp.status_code == 200
|
|
html = resp.text
|
|
for bad in ("font-size:11px", "font-size:12px", "font-size: 11px", "font-size: 12px"):
|
|
assert bad not in html, f"Bara de status foloseste {bad} (sub 13px)."
|