Files

43 lines
1.8 KiB
Python
Raw Permalink Normal View History

"""Change C3 (Gitea issue 25): FILE is refused while the packet's unit has an ITP that is not complete. A unit with
no ITP does not block. The reason shows in `blocked.file` so the close panel says why."""
from __future__ import annotations
from collections.abc import Iterator
import pytest
from closehelpers import at_complete, file_packet, vclose
from fakedir import FakeDirectory
from pshelpers import needs_pg
from qchelpers import start_itp
from shophelpers import Shop, fresh, make_unit, ok, open_shop, refused, run
from packetstation.settings import Settings
pytestmark = needs_pg
MSG = "Complete the unit's ITP first. Q.C. signs it off on the ITP page."
@pytest.fixture
def shop(pg_settings: Settings, fake_dir: FakeDirectory, dev_visual: None) -> Iterator[Shop]:
yield from open_shop(pg_settings, fake_dir)
def test_open_itp_blocks_the_file_until_signed_off(shop: Shop) -> None:
_, unit_id = make_unit(shop.settings)
pkt = vclose(shop, at_complete(shop, unit_id))
pid = pkt["id"]
assert "file" in pkt["can"] # no ITP on the unit: nothing blocks
itp = start_itp(shop, unit_id)
view = fresh(shop("clerk.clara"), pid)
assert "file" not in view["can"] and view["blocked"]["file"] == [MSG]
[card] = ok(shop("clerk.clara").get(f"/api/packets?unit_id={unit_id}"))["packets"]
assert card["blocked"]["file"] == [MSG]
refused(file_packet(shop, view), 403, "precondition", MSG)
# the ITP sign-off itself is tested in test_itp.py; here its end state is enough
run(shop.settings, "UPDATE itps SET status = 'complete', signoff_at = now() WHERE id = %s", (itp["id"],))
view = fresh(shop("clerk.clara"), pid)
assert "file" in view["can"] and "file" not in view["blocked"]
assert ok(file_packet(shop, view))["status"] == "filed"