107 lines
3.5 KiB
Python
107 lines
3.5 KiB
Python
"""Layout regression tests for task 023-FIX2: project header + payments actions."""
|
|
import re
|
|
import shutil
|
|
|
|
from fastapi.testclient import TestClient
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy.orm import sessionmaker
|
|
|
|
from app.database.database import Base, DATABASE_PATH
|
|
from app.main import app
|
|
from app.models.project import Project
|
|
from app.models.payment import Payment
|
|
from app.routers import (
|
|
projects as project_router,
|
|
payments as payments_router,
|
|
boq as boq_router,
|
|
ks2 as ks2_router,
|
|
ks3 as ks3_router,
|
|
)
|
|
|
|
|
|
def _make_session(tmp_path):
|
|
db_path = tmp_path / "t023fix2.db"
|
|
shutil.copy2(DATABASE_PATH, db_path)
|
|
engine = create_engine(f"sqlite:///{db_path.as_posix()}", connect_args={"check_same_thread": False})
|
|
Base.metadata.create_all(bind=engine)
|
|
return engine, sessionmaker(bind=engine, autoflush=False, autocommit=False)
|
|
|
|
|
|
DEPS = (
|
|
project_router.get_db,
|
|
payments_router.get_db,
|
|
boq_router.get_db,
|
|
ks2_router.get_db,
|
|
ks3_router.get_db,
|
|
)
|
|
|
|
|
|
def _bind(Session):
|
|
def override_db():
|
|
s = Session()
|
|
try:
|
|
yield s
|
|
finally:
|
|
s.close()
|
|
for dep in DEPS:
|
|
app.dependency_overrides[dep] = override_db
|
|
|
|
|
|
def _clear():
|
|
for dep in DEPS:
|
|
app.dependency_overrides.pop(dep, None)
|
|
|
|
|
|
def test_project_header_requisites_are_separate_blocks(tmp_path):
|
|
engine, Session = _make_session(tmp_path)
|
|
_bind(Session)
|
|
try:
|
|
with Session() as s:
|
|
p = Project(name="Header FIX2", contract_number="D-1", customer="Cust", status="active")
|
|
s.add(p)
|
|
s.commit()
|
|
pid = p.id
|
|
with TestClient(app) as client:
|
|
html = client.get(f"/projects/{pid}").text
|
|
# Each requisite is its own labeled block, not one inline string
|
|
for label in ("Договор", "Заказчик", "Валюта", "Период", "Статус"):
|
|
assert f'class="text-muted small mb-1">{label}</div>' in html
|
|
# Bootstrap row with gaps on requisites container
|
|
assert re.search(r'class="row g-3 g-md-4', html)
|
|
# Top row still has name + actions
|
|
assert "Дневной отчёт" in html and "Редактировать" in html
|
|
finally:
|
|
_clear()
|
|
engine.dispose()
|
|
|
|
|
|
def test_payments_actions_are_nowrap_inline(tmp_path):
|
|
from datetime import date
|
|
from decimal import Decimal
|
|
engine, Session = _make_session(tmp_path)
|
|
_bind(Session)
|
|
try:
|
|
with Session() as s:
|
|
p = Project(name="Pay FIX2")
|
|
s.add(p)
|
|
s.flush()
|
|
s.add(Payment(project_id=p.id, date=date(2026, 1, 1), amount=Decimal("10"),
|
|
currency="RUB", status="cancelled"))
|
|
s.commit()
|
|
pid = p.id
|
|
with TestClient(app) as client:
|
|
html = client.get(f"/projects/{pid}/payments").text
|
|
# Actions cell keeps all three actions on one line
|
|
assert "payments-actions" in html
|
|
assert "text-nowrap" in html
|
|
assert "d-inline-flex" in html
|
|
# Column width reserved
|
|
assert re.search(r'<col style="width: 17rem">', html)
|
|
# Three actions + storno badge + row-click preserved
|
|
assert "Просмотр" in html and "Редактировать" in html and "Удалить" in html
|
|
assert "Сторнирован" in html
|
|
assert "clickable-row" in html
|
|
finally:
|
|
_clear()
|
|
engine.dispose()
|