По плану docs/PLAN_2026-11-21_reviewer_workspace.md: POST /api/review/docs принимает машиночитаемую смету .gge (до 20 МБ), разбирает её и отдаёт позиции; список и выдача своих смет — только владельцу (чужой и несуществующий — одинаково 404). Страница /review/workspace: загрузка, выбор сметы, поиск, таблица позиций; в шапке ссылки пока нет. Пустой, битый и не-.gge файл объясняются словами. Тесты краснеют от мутаций (проверка расширения, владельца). Co-Authored-By: Claude Code <noreply@anthropic.com>
102 lines
4.5 KiB
Python
102 lines
4.5 KiB
Python
"""Рабочее место проверяющего, этап 0: загрузка машиночитаемой сметы и её позиции.
|
|
|
|
План — docs/PLAN_2026-11-21_reviewer_workspace.md. Приёмка этапа: файл .gge
|
|
загружается, позиции возвращаются таблицей, чужой не видит документ, пустой и битый
|
|
файл объясняются словами. Программа на компьютере эксперта не нужна.
|
|
|
|
Mutation: не проверять владельца — падает «чужой не видит»; не проверять расширение —
|
|
падает отказ битому файлу; не сохранять строки — падает выдача.
|
|
"""
|
|
import importlib
|
|
import io
|
|
import os
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
|
|
ROOT = Path(__file__).resolve().parent.parent
|
|
sys.path.insert(0, str(ROOT))
|
|
FIX = ROOT / "tests" / "fixtures" / "review_small.gge"
|
|
|
|
|
|
@pytest.fixture()
|
|
def env(tmp_path, monkeypatch):
|
|
monkeypatch.setenv("DB_PATH", str(tmp_path / "t.db"))
|
|
monkeypatch.setenv("DATA_DIR", str(tmp_path / "data"))
|
|
monkeypatch.setenv("SESSION_SECRET", "test-secret")
|
|
monkeypatch.setenv("AI_BACKEND", "claude")
|
|
monkeypatch.chdir(ROOT)
|
|
import auth
|
|
import db
|
|
import main
|
|
for m in (db, auth, main):
|
|
importlib.reload(m)
|
|
db.init_db()
|
|
for u in ("checker@x", "other@x"):
|
|
db.create_user(u, "h")
|
|
db.admin_verify_user(u)
|
|
from fastapi.testclient import TestClient
|
|
client = TestClient(main.app)
|
|
return db, auth, client
|
|
|
|
|
|
def _h(auth, user="checker@x"):
|
|
return {"Authorization": "Bearer " + auth._make_token(user)}
|
|
|
|
|
|
def _upload(client, auth, name="ЛС-01.gge", data=None, user="checker@x"):
|
|
body = data if data is not None else FIX.read_bytes()
|
|
return client.post("/api/review/docs", headers=_h(auth, user),
|
|
files={"file": (name, io.BytesIO(body),
|
|
"application/octet-stream")})
|
|
|
|
|
|
def test_upload_returns_positions(env):
|
|
db, auth, client = env
|
|
r = _upload(client, auth)
|
|
assert r.status_code == 200, r.text
|
|
d = r.json()
|
|
assert d["title"] == "Смета для проверки замечаний" and d["code"] == "ЛС-01"
|
|
assert [p["code"] for p in d["positions"]] == ["01-01-001-01", "06-01-001-02",
|
|
"09-03-001-01"]
|
|
first = d["positions"][0]
|
|
assert first["unit"] == "м3" and first["quantity"] == 100
|
|
assert client.get(f"/api/review/docs/{d['id']}", headers=_h(auth)).json()["positions"]
|
|
assert [x["id"] for x in client.get("/api/review/docs", headers=_h(auth)).json()["items"]] == [d["id"]]
|
|
|
|
|
|
def test_foreign_checker_cannot_see_document(env):
|
|
db, auth, client = env
|
|
did = _upload(client, auth).json()["id"]
|
|
assert client.get(f"/api/review/docs/{did}", headers=_h(auth, "other@x")).status_code == 404
|
|
assert client.get("/api/review/docs", headers=_h(auth, "other@x")).json()["items"] == []
|
|
|
|
|
|
def test_wrong_and_broken_files_explained(env):
|
|
db, auth, client = env
|
|
r = _upload(client, auth, name="smeta.xlsx", data=b"PK\x03\x04")
|
|
assert r.status_code == 400 and ".gge" in r.text
|
|
r = _upload(client, auth, data=b"<not-xml")
|
|
assert r.status_code == 400 and "разобр" in r.text.lower()
|
|
empty = b'<LocalEstimate><Estimate><Num>1</Num><Name>x</Name></Estimate></LocalEstimate>'
|
|
r = _upload(client, auth, data=empty)
|
|
assert r.status_code == 400 and "позиц" in r.text.lower()
|
|
|
|
|
|
def test_upload_requires_login(env):
|
|
db, auth, client = env
|
|
r = client.post("/api/review/docs", files={"file": ("x.gge", io.BytesIO(FIX.read_bytes()))})
|
|
assert r.status_code == 401
|
|
|
|
|
|
def test_workspace_page_has_real_actions_only(env):
|
|
"""Страница этапа 0 — не заглушка: загрузка, поиск и таблица; никакой программы на
|
|
компьютере и кодов подключения (это и была «залепуха», Хозяин 21.11.2026)."""
|
|
html = (ROOT / "static" / "review-workspace.html").read_text(encoding="utf-8")
|
|
for text in ("Загрузить смету", 'accept=".gge"', 'id="search"', "Стоимость, ₽",
|
|
"/api/review/docs"):
|
|
assert text in html, text
|
|
for лишнее in ("Получить код", "программа", "Программа"):
|
|
assert лишнее not in html, лишнее
|