feat: UI/UX cleanup V1 with header, import requisites, and status fixes

This commit is contained in:
Арсентьев Александр
2026-09-27 20:22:13 +03:00
parent 79d802d536
commit 94571f9684
31 changed files with 2842 additions and 73 deletions
+443
View File
@@ -0,0 +1,443 @@
"""Regression tests for task 023: UI/UX cleanup V1."""
import shutil
from datetime import date
from decimal import Decimal
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.importer.excel_importer import import_excel_data
from app.main import app
from app.models.project import Project
from app.models.boq import BoqDocument, System, Section, WorkItem
from app.models.agreement import Agreement
from app.models.daily_report import DailyReport, DailyReportItem
from app.routers import (
projects as project_router,
boq as boq_router,
agreements as agreement_router,
daily_reports,
ks2 as ks2_router,
ks3 as ks3_router,
payments as payments_router,
)
def _make_session(tmp_path):
db_path = tmp_path / "t023-copy.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)
def _override(*deps):
# Use the first dep's session factory via closure over module-level Session
pass
def _bind_session(Session, *deps):
def override_db():
s = Session()
try:
yield s
finally:
s.close()
for dep in deps:
app.dependency_overrides[dep] = override_db
def _clear(*deps):
for dep in deps:
app.dependency_overrides.pop(dep, None)
ALL_DEPS = (
project_router.get_db,
boq_router.get_db,
agreement_router.get_db,
daily_reports.get_db,
ks2_router.get_db,
ks3_router.get_db,
payments_router.get_db,
)
def _seed_project(Session):
with Session() as s:
p = Project(name="UI cleanup", status="active", contract_number="D-1")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="BOQ Import - Ведомость ОВ")
s.add(doc)
s.flush()
system = System(project_id=p.id, name="Система", sort_order=1)
s.add(system)
s.flush()
section = Section(system_id=system.id, name="Раздел", sort_order=1)
s.add(section)
s.flush()
item = WorkItem(
project_id=p.id, boq_document_id=doc.id, system_id=system.id, section_id=section.id,
source_number="1", name="Позиция", unit="шт", quantity=10,
unit_price=Decimal("100"), amount=Decimal("1000"),
)
s.add(item)
s.commit()
return p.id, doc.id, item.id
# --- 1/2. Agreements row-click markup ---
def test_agreement_list_rows_are_clickable(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid, doc_id, _ = _seed_project(Session)
with Session() as s:
agr = Agreement(
project_id=pid, number="A-1", date=date(2026, 1, 1),
title="ДС", status="draft",
)
s.add(agr)
s.commit()
agr_id = agr.id
with TestClient(app) as client:
resp = client.get(f"/projects/{pid}/agreements")
assert resp.status_code == 200
html = resp.text
assert f'data-url="/projects/{pid}/agreements/{agr_id}"' in html
assert "clickable-row" in html
# Action button must not fall through to row navigation
assert "e.target.closest('a, button, form, input, select, textarea')" in html
assert f'href="/projects/{pid}/agreements/{agr_id}"' in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
# --- 3. BOQ display name in agreement scope selector ---
def test_agreement_scope_shows_display_name_not_technical(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid, doc_id, _ = _seed_project(Session)
with TestClient(app) as client:
resp = client.get(f"/projects/{pid}/agreements/new")
assert resp.status_code == 200
html = resp.text
assert "Ведомость ОВ" in html
assert "BOQ Import" not in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_boq_display_name_property():
doc = BoqDocument(id=1, project_id=1, name="BOQ Import - Ведомость ОВ")
assert doc.display_name == "Ведомость ОВ"
doc2 = BoqDocument(id=2, project_id=1, name="Импорт ведомости — Лист 1")
assert doc2.display_name == "Лист 1"
doc3 = BoqDocument(id=3, project_id=1, name="Основная ведомость")
assert doc3.display_name == "Основная ведомость"
# --- 4. Import requisites ---
def test_import_excel_saves_document_requisites(tmp_path):
import openpyxl
path = tmp_path / "boq.xlsx"
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Ведомость ОВ"
for _ in range(4):
ws.append([None])
ws.append(["№", "Наименование", "Модель", "Производитель", "Ед", "Кол-во", "Цена", "Сумма"])
ws.append([1, "Работа", None, None, "шт", 2, 10, 20])
wb.save(path)
engine = create_engine("sqlite:///:memory:")
Base.metadata.create_all(engine)
session = sessionmaker(bind=engine)()
project = Project(name="Import requisites")
session.add(project)
session.commit()
result = import_excel_data(
session, str(path), "Ведомость ОВ", 5, 6, project.id,
document_name="Основная ведомость",
document_number="БО-01",
document_date=date(2026, 3, 1),
contract="Договор 42",
)
doc = session.get(BoqDocument, result["document_id"])
assert doc.name == "Основная ведомость"
assert doc.document_number == "БО-01"
assert doc.document_date == date(2026, 3, 1)
assert doc.contract == "Договор 42"
assert doc.display_name == "Основная ведомость"
session.close()
def test_import_preview_exposes_requisites_fields(tmp_path):
import openpyxl
path = tmp_path / "boq.xlsx"
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Лист1"
for _ in range(4):
ws.append([None])
ws.append(["№", "Наименование", "Модель", "Производитель", "Ед", "Кол-во", "Цена", "Сумма"])
ws.append([1, "Работа", None, None, "шт", 1, 5, 5])
upload_dir = tmp_path / "uploads"
upload_dir.mkdir()
saved = upload_dir / "boq.xlsx"
wb.save(saved)
engine, Session = _make_session(tmp_path)
_bind_session(Session, boq_router.get_db, project_router.get_db)
try:
with Session() as s:
p = Project(name="Import UI", contract_number="PC-9")
s.add(p)
s.commit()
pid = p.id
# Point UPLOAD_DIR at temp
import app.routers.boq as boq_mod
old_upload = boq_mod.UPLOAD_DIR
boq_mod.UPLOAD_DIR = upload_dir
try:
with TestClient(app) as client:
resp = client.post(f"/boq/{pid}/import/preview", data={
"filename": "boq.xlsx",
"sheet_name": "Лист1",
"header_row": "5",
"start_row": "6",
})
assert resp.status_code == 200
html = resp.text
assert 'name="document_name"' in html
assert 'name="document_number"' in html
assert 'name="document_date"' in html
assert 'name="contract"' in html
assert "Реквизиты ведомости" in html
# Default name comes from sheet
assert "Лист1" in html
finally:
boq_mod.UPLOAD_DIR = old_upload
finally:
_clear(boq_router.get_db, project_router.get_db)
engine.dispose()
# --- 5. Delete project blocked → UI modal, not raw JSON to browser ---
def test_delete_project_blocked_keeps_api_json_and_page_has_modal(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Has history")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="BOQ")
s.add(doc)
s.flush()
item = WorkItem(project_id=p.id, boq_document_id=doc.id, name="I", quantity=1)
s.add(item)
s.flush()
dr = DailyReport(project_id=p.id, report_date=date(2026, 1, 1))
s.add(dr)
s.flush()
s.add(DailyReportItem(daily_report_id=dr.id, work_item_id=item.id, completed_quantity=1))
s.commit()
pid = p.id
with TestClient(app) as client:
# API contract preserved for non-browser clients
resp = client.post(f"/projects/{pid}/delete", follow_redirects=False)
assert resp.status_code == 400
assert resp.json()["detail"]
# Browser UI: page contains modal + JS handler, not a bare form post
page = client.get(f"/projects/{pid}")
html = page.text
assert 'id="deleteBlockedModal"' in html
assert "Проект нельзя удалить" in html
assert "Рекомендуется архивировать проект" in html
assert "Архивировать проект" in html
assert 'id="delete-project-form"' in html
assert "bootstrap.Modal" in html
# Status badge is visually distinct
assert "text-bg-success" in html # active
# Daily report button near top / status block
assert "Дневной отчёт" in html
# Package button is not full-width
assert "Сформировать комплект" in html
assert "btn-primary w-100" not in html or "Сформировать комплект" not in html.split("btn-primary w-100")[0][-50:]
# Eye toggle is separated from business nav
assert "Финансовые суммы" in html
# BOQ and DS are adjacent entry points
assert "Ведомости" in html and "Дополнительные соглашения" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_delete_project_without_related_data_still_works(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Clean")
s.add(p)
s.commit()
pid = p.id
with TestClient(app) as client:
resp = client.post(f"/projects/{pid}/delete", follow_redirects=False)
assert resp.status_code == 303
with Session() as s:
assert s.get(Project, pid) is None
finally:
_clear(*ALL_DEPS)
engine.dispose()
# --- 6. Existing import flow still works ---
def test_import_confirm_flow_still_works(tmp_path):
import openpyxl
path = tmp_path / "boq.xlsx"
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Ведомость"
for _ in range(4):
ws.append([None])
ws.append(["№", "Наименование", "Модель", "Производитель", "Ед", "Кол-во", "Цена", "Сумма"])
ws.append([1, "Работа", None, None, "шт", 1, 5, 5])
upload_dir = tmp_path / "uploads"
upload_dir.mkdir()
wb.save(upload_dir / "boq.xlsx")
engine, Session = _make_session(tmp_path)
_bind_session(Session, boq_router.get_db, project_router.get_db)
try:
with Session() as s:
p = Project(name="Import flow")
s.add(p)
s.commit()
pid = p.id
import app.routers.boq as boq_mod
old_upload = boq_mod.UPLOAD_DIR
boq_mod.UPLOAD_DIR = upload_dir
try:
with TestClient(app) as client:
resp = client.post(f"/boq/{pid}/import/confirm", data={
"filename": "boq.xlsx",
"sheet_name": "Ведомость",
"header_row": "5",
"start_row": "6",
"document_name": "Моя ведомость",
"document_number": "12",
"document_date": "2026-02-02",
"contract": "К-1",
})
assert resp.status_code == 200
assert "Импорт завершен" in resp.text
assert "Моя ведомость" in resp.text
finally:
boq_mod.UPLOAD_DIR = old_upload
with Session() as s:
doc = s.query(BoqDocument).filter_by(project_id=pid).one()
assert doc.name == "Моя ведомость"
assert doc.document_number == "12"
assert doc.document_date == date(2026, 2, 2)
assert doc.contract == "К-1"
items = s.query(WorkItem).filter_by(boq_document_id=doc.id).all()
assert len(items) == 1
finally:
_clear(boq_router.get_db, project_router.get_db)
engine.dispose()
# --- 7. Eye toggle not broken ---
def test_eye_toggle_present_on_project_and_base_pages(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid, doc_id, _ = _seed_project(Session)
with TestClient(app) as client:
project_page = client.get(f"/projects/{pid}")
assert "id=\"toggleMoney\"" in project_page.text
assert "money-hidden" in project_page.text
assert "classList.toggle('money-hidden')" in project_page.text
boq_page = client.get(f"/boq/{pid}/documents/{doc_id}")
assert "id=\"toggleMoney\"" in boq_page.text
assert "money-hidden" in boq_page.text
# KS-2 / KS-3 / Payments pages extend base.html
for path in (f"/projects/{pid}/ks2", f"/projects/{pid}/ks3", f"/projects/{pid}/payments"):
page = client.get(path)
assert page.status_code == 200
assert "id=\"toggleMoney\"" in page.text
assert "money-hidden" in page.text
finally:
_clear(*ALL_DEPS)
engine.dispose()
# --- Status badge + package button + requisites shown ---
def test_project_page_status_badge_and_package_button(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Status", status="on_hold")
s.add(p)
s.commit()
pid = p.id
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
assert "text-bg-warning" in html # on_hold
assert "Приостановлен" in html
# Package button is normal size (no w-100 on that button)
import re
match = re.search(r'<button type="submit" class="([^"]*)">Сформировать комплект</button>', html)
assert match
assert "w-100" not in match.group(1)
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_boq_document_shows_requisites(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Req display")
s.add(p)
s.flush()
doc = BoqDocument(
project_id=p.id, name="Основная ведомость",
document_number="БО-7", document_date=date(2026, 5, 5),
contract="Договор 1",
)
s.add(doc)
s.commit()
pid, did = p.id, doc.id
with TestClient(app) as client:
html = client.get(f"/boq/{pid}/documents/{did}").text
assert "Основная ведомость" in html
assert "БО-7" in html
assert "Договор 1" in html
assert "05.05.2026" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
+106
View File
@@ -0,0 +1,106 @@
"""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()
+146
View File
@@ -0,0 +1,146 @@
"""Layout tests for task 023-FIX3: project header composition + doc nav row."""
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.boq import BoqDocument
from app.routers import (
projects as project_router,
boq as boq_router,
agreements as agreement_router,
daily_reports,
ks2 as ks2_router,
ks3 as ks3_router,
payments as payments_router,
)
def _make_session(tmp_path):
db_path = tmp_path / "t023fix3.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,
boq_router.get_db,
agreement_router.get_db,
daily_reports.get_db,
ks2_router.get_db,
ks3_router.get_db,
payments_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 _seed(Session):
with Session() as s:
p = Project(name="FIX3", status="active")
s.add(p)
s.flush()
s.add(BoqDocument(project_id=p.id, name="Ведомость ОВ"))
s.commit()
return p.id
NAV_HREFS = [
"/boq/{pid}",
"/projects/{pid}/agreements",
"/projects/{pid}/daily-reports",
"/projects/{pid}/ks2",
"/projects/{pid}/ks3",
"/projects/{pid}/ks6a",
"/projects/{pid}/payments",
]
def test_doc_nav_has_all_seven_buttons_in_one_row(tmp_path):
engine, Session = _make_session(tmp_path)
_bind(Session)
try:
pid = _seed(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
nav = re.search(r'<nav class="doc-nav[^"]*"[^>]*>(.*?)</nav>', html, re.S)
assert nav, "doc-nav block missing"
block = nav.group(1)
for href in NAV_HREFS:
assert f'href="{href.format(pid=pid)}"' in block, href
# Exactly 7 nav buttons in the block
assert block.count('class="btn btn-outline-primary"') == 7
finally:
_clear()
engine.dispose()
def test_doc_nav_has_no_horizontal_scroll_wrapper(tmp_path):
engine, Session = _make_session(tmp_path)
_bind(Session)
try:
pid = _seed(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
nav = re.search(r'<nav class="doc-nav([^"]*)"', html)
assert nav
classes = nav.group(1)
assert "overflow" not in classes
assert "table-responsive" not in classes
# CSS: nowrap flex, no overflow-x
assert ".doc-nav" in html
assert "flex-wrap: nowrap" in html
assert "overflow-x" not in html
finally:
_clear()
engine.dispose()
def test_header_order_and_eye_toggle_separate(tmp_path):
engine, Session = _make_session(tmp_path)
_bind(Session)
try:
pid = _seed(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
# Actions under title, not in a justify-content-between top row
assert "Дневной отчёт" in html
assert "Редактировать" in html
# Requisites remain separate blocks
for label in ("Договор", "Заказчик", "Валюта", "Период", "Статус"):
assert f'class="text-muted small mb-1">{label}</div>' in html
# BOQ line
assert "Ведомость проекта:" in html
# Eye toggle is outside doc-nav and before План и выполнение
nav_end = html.find("</nav>")
plan_pos = html.find("План и выполнение")
eye_pos = html.find('id="toggleMoney"')
assert 0 < nav_end < eye_pos < plan_pos
assert "Финансовые суммы" in html
# Archive / delete still present
assert "Архивировать" in html or "Проект архивирован" in html
assert "delete-project-form" in html or "Проект архивирован" in html
finally:
_clear()
engine.dispose()
+372
View File
@@ -0,0 +1,372 @@
"""Regression tests for task 023-FIX: UI/UX follow-up after visual review."""
import re
import shutil
from datetime import date
from decimal import Decimal
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.boq import BoqDocument, System, Section, WorkItem
from app.models.agreement import Agreement
from app.models.ks2 import KS2
from app.models.ks3 import KS3
from app.models.payment import Payment
from app.routers import (
projects as project_router,
boq as boq_router,
agreements as agreement_router,
daily_reports,
ks2 as ks2_router,
ks3 as ks3_router,
payments as payments_router,
)
def _make_session(tmp_path):
db_path = tmp_path / "t023fix-copy.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)
ALL_DEPS = (
project_router.get_db,
boq_router.get_db,
agreement_router.get_db,
daily_reports.get_db,
ks2_router.get_db,
ks3_router.get_db,
payments_router.get_db,
)
def _bind_session(Session, *deps):
def override_db():
s = Session()
try:
yield s
finally:
s.close()
for dep in deps:
app.dependency_overrides[dep] = override_db
def _clear(*deps):
for dep in deps:
app.dependency_overrides.pop(dep, None)
# 1. Document tree has both entry points
def test_document_tree_has_boq_and_agreements_buttons(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Tree buttons")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="Ведомость")
s.add(doc)
s.flush()
agr = Agreement(project_id=p.id, number="A-1", date=date(2026, 1, 1), title="ДС", status="draft")
s.add(agr)
s.commit()
pid, doc_id, agr_id = p.id, doc.id, agr.id
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
# Both buttons present in the document-tree card header
tree_block = html.split("Дерево документов", 1)[-1].split("</section>", 1)[0]
assert f'href="/boq/{pid}"' in tree_block
assert f'href="/projects/{pid}/agreements"' in tree_block
assert "Дополнительные соглашения" in tree_block
assert "Ведомости" in tree_block
finally:
_clear(*ALL_DEPS)
engine.dispose()
# 2. Import requisites are on the initial import form and pass through
def test_import_form_shows_all_four_requisites(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Import form", contract_number="PC-1")
s.add(p)
s.commit()
pid = p.id
with TestClient(app) as client:
html = client.get(f"/projects/{pid}/import").text
assert 'name="document_name"' in html
assert 'name="document_number"' in html
assert 'name="document_date"' in html
assert 'name="contract"' in html
assert "Реквизиты ведомости" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_import_requisites_pass_upload_to_confirm(tmp_path):
import openpyxl
wb = openpyxl.Workbook()
ws = wb.active
ws.title = "Лист А"
for _ in range(4):
ws.append([None])
ws.append(["№", "Наименование", "Модель", "Производитель", "Ед", "Кол-во", "Цена", "Сумма"])
ws.append([1, "Работа", None, None, "шт", 1, 5, 5])
upload_dir = tmp_path / "uploads"
upload_dir.mkdir()
wb.save(upload_dir / "file.xlsx")
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Flow")
s.add(p)
s.commit()
pid = p.id
import app.routers.boq as boq_mod
old_upload = boq_mod.UPLOAD_DIR
boq_mod.UPLOAD_DIR = upload_dir
try:
with TestClient(app) as client:
# upload carries requisites into sheet selection
with open(upload_dir / "file.xlsx", "rb") as fh:
up = client.post(
f"/boq/{pid}/import/upload",
files={"file": ("file.xlsx", fh, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")},
data={
"document_name": "Ведомость А",
"document_number": "N-1",
"document_date": "2026-04-01",
"contract": "Д-9",
},
)
assert up.status_code == 200
assert 'value="Ведомость А"' in up.text
assert 'value="N-1"' in up.text
assert 'value="Д-9"' in up.text
# preview shows requisites
prev = client.post(f"/boq/{pid}/import/preview", data={
"filename": "file.xlsx",
"sheet_name": "Лист А",
"header_row": "5",
"start_row": "6",
"document_name": "Ведомость А",
"document_number": "N-1",
"document_date": "2026-04-01",
"contract": "Д-9",
})
assert prev.status_code == 200
assert "Реквизиты ведомости" in prev.text
assert "Ведомость А" in prev.text
assert "N-1" in prev.text
# confirm saves
conf = client.post(f"/boq/{pid}/import/confirm", data={
"filename": "file.xlsx",
"sheet_name": "Лист А",
"header_row": "5",
"start_row": "6",
"document_name": "Ведомость А",
"document_number": "N-1",
"document_date": "2026-04-01",
"contract": "Д-9",
})
assert conf.status_code == 200
assert "Ведомость А" in conf.text
finally:
boq_mod.UPLOAD_DIR = old_upload
with Session() as s:
doc = s.query(BoqDocument).filter_by(project_id=pid).one()
assert doc.name == "Ведомость А"
assert doc.document_number == "N-1"
assert doc.document_date == date(2026, 4, 1)
assert doc.contract == "Д-9"
assert doc.display_name == "Ведомость А"
finally:
_clear(*ALL_DEPS)
engine.dispose()
# 3. display_name used in UI
def test_display_name_used_in_agreement_scope(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="DN")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="BOQ Import - Ведомость ОВ")
s.add(doc)
s.commit()
pid = p.id
with TestClient(app) as client:
html = client.get(f"/projects/{pid}/agreements/new").text
assert "Ведомость ОВ" in html
assert "BOQ Import" not in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
# 4-6. Status in KS-2 / KS-3 / Payments lists
def _seed_ks_and_payments(Session):
with Session() as s:
p = Project(name="Status lists")
s.add(p)
s.flush()
doc = BoqDocument(project_id=p.id, name="BOQ")
s.add(doc)
s.flush()
wi = WorkItem(project_id=p.id, boq_document_id=doc.id, name="W", quantity=Decimal("1"), amount=Decimal("10"))
s.add(wi)
s.flush()
ks2_draft = KS2(project_id=p.id, number="K2-1", date=date(2026, 1, 1), status="draft")
ks2_issued = KS2(project_id=p.id, number="K2-2", date=date(2026, 1, 2), status="issued")
ks2_cancelled = KS2(project_id=p.id, number="K2-3", date=date(2026, 1, 3), status="cancelled")
s.add_all([ks2_draft, ks2_issued, ks2_cancelled])
s.flush()
ks3_draft = KS3(project_id=p.id, number="K3-1", date=date(2026, 2, 1), status="draft")
ks3_issued = KS3(project_id=p.id, number="K3-2", date=date(2026, 2, 2), status="issued")
ks3_cancelled = KS3(project_id=p.id, number="K3-3", date=date(2026, 2, 3), status="cancelled")
s.add_all([ks3_draft, ks3_issued, ks3_cancelled])
s.flush()
pay_active = Payment(project_id=p.id, date=date(2026, 3, 1), amount=Decimal("5"), currency="RUB", status="active")
pay_cancelled = Payment(project_id=p.id, date=date(2026, 3, 2), amount=Decimal("5"), currency="RUB", status="cancelled")
s.add_all([pay_active, pay_cancelled])
s.commit()
return p.id
def test_ks2_list_shows_all_statuses(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid = _seed_ks_and_payments(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}/ks2").text
assert "Черновик" in html
assert "Проведён" in html
assert "Сторнирован" in html
assert "badge" in html
assert "bg-danger" in html
assert "bg-success" in html
assert "bg-secondary" in html
# row-click preserved
assert "clickable-row" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_ks3_list_shows_all_statuses(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid = _seed_ks_and_payments(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}/ks3").text
assert "Черновик" in html
assert "Проведён" in html
assert "Сторнирован" in html
assert "badge" in html
assert "clickable-row" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_payments_list_shows_status(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
pid = _seed_ks_and_payments(Session)
with TestClient(app) as client:
html = client.get(f"/projects/{pid}/payments").text
assert "Сторнирован" in html
assert "Активный" in html
assert "Статус" in html
assert "badge" in html
assert "clickable-row" in html
finally:
_clear(*ALL_DEPS)
engine.dispose()
# 7. Existing tests + regressions: header layout, package button
def test_project_header_layout_and_package_button(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Header", status="active", contract_number="D-1", customer="Cust")
s.add(p)
s.commit()
pid = p.id
with TestClient(app) as client:
html = client.get(f"/projects/{pid}").text
# Top row: project name and primary actions
assert "Дневной отчёт" in html
assert "Редактировать" in html
# Requisites readable
assert "D-1" in html
assert "Cust" in html
assert "Активный" in html
# Package button is not full-width / not stretched
match = re.search(r'<button type="submit" class="([^"]*)">Сформировать комплект</button>', html)
assert match, "package button not found"
assert "w-100" not in match.group(1)
assert "w-auto" in match.group(1)
assert "text-nowrap" in match.group(1)
finally:
_clear(*ALL_DEPS)
engine.dispose()
def test_eye_toggle_and_agreement_create_not_broken(tmp_path):
engine, Session = _make_session(tmp_path)
_bind_session(Session, *ALL_DEPS)
try:
with Session() as s:
p = Project(name="Regressions")
s.add(p)
s.flush()
BoqDocument(project_id=p.id, name="BOQ Import - Ведомость ОВ")
s.commit()
pid = p.id
with TestClient(app) as client:
page = client.get(f"/projects/{pid}")
assert 'id="toggleMoney"' in page.text
assert "money-hidden" in page.text
form = client.get(f"/projects/{pid}/agreements/new")
assert form.status_code == 200
created = client.post(f"/projects/{pid}/agreements", data={
"number": "A-1", "agreement_date": "2026-01-01",
"title": "Тест", "description": "", "scope": "project",
}, follow_redirects=False)
assert created.status_code == 303
# agreement list row-click
listing = client.get(f"/projects/{pid}/agreements")
assert "clickable-row" in listing.text
finally:
_clear(*ALL_DEPS)
engine.dispose()