Files

53 lines
2.1 KiB
Python
Raw Permalink Normal View History

"""qc_reject is raised in the write's transaction: a Q.C. reject of a packet (its department) and an ITP line reject
(the department working to the line's page, when only one does)."""
from __future__ import annotations
from collections.abc import Iterator
import pytest
from fakedir import FakeDirectory
from pshelpers import needs_pg
from qchelpers import at_qc, open_qc_shop, reject, reject_line, start_itp
from shophelpers import Shop, make_unit, ok, one
from packetstation.settings import Settings
pytestmark = needs_pg
@pytest.fixture
def shop(pg_settings: Settings, fake_dir: FakeDirectory, dev_visual: None) -> Iterator[Shop]:
yield from open_qc_shop(pg_settings, fake_dir)
def test_qc_and_itp_rejects_raise_qc_reject(shop: Shop) -> None:
pkt = at_qc(shop)
ok(reject(shop, pkt, "Weld 2 undercut too deep"))
row = one(
shop.settings,
"SELECT kind, event_type, subject, dept_code, title, body, resolved_at, dispatched_at"
" FROM notification_events WHERE event_type = 'qc_reject'",
)
assert row[0] == row[1] == "qc_reject"
dept = one(shop.settings, "SELECT dept_code FROM packets WHERE id = %s", (pkt["id"],))[0]
assert row[2] == f"packet:{pkt['id']}" and row[3] == dept == "03"
assert row[4].startswith(f"Q.C. rejected packet {pkt['id']}")
assert "Weld 2 undercut too deep" in row[5] and "Quinn QC" in row[5]
assert row[6] is not None and row[7] is None # a one-shot, waiting for notify-send
_, unit_id = make_unit(shop.settings)
itp = start_itp(shop, unit_id)
ok(reject_line(shop("qc.quinn"), itp, "1.4", note="Manual is rev C"))
row = one(
shop.settings,
"SELECT subject, dept_code, title, body, detail FROM notification_events"
" WHERE event_type = 'qc_reject' AND subject <> %s",
(f"packet:{pkt['id']}",),
)
assert row[0] == f"itp:{itp['id']}:1.4"
assert row[1] is None # no packet of that unit works to the page
assert row[2].startswith(f"ITP {itp['no']} line 1.4 rejected")
assert "NCR # pending" in row[3] and "Manual is rev C" in row[3]
assert row[4]["line"] == "1.4" and row[4]["itp_id"] == itp["id"]