- migration 20261018170000: pgmq badge_print/badge_print_dlq, print_stations, token-gated printer RPCs (claim/complete/fail/heartbeat), admin RPCs, welcome_checkin enqueue; badge_print_tests.sql (101 assertions) - apps/printer: Python worker (Playwright render -> brother_ql via pyusb), comitup captive-portal (Wi-Fi + HTTPS endpoint + anon key + token), arm64 image build + idempotent Pi setup/install scripts, 77 pytest - apps/admin: Printing view, station management/DLQ, global printer status pill, Print button on Registrations, standalone print renderer entry (print.html -> dist-print) with bundled fonts - docs: printing.md + architecture/schema/rpcs/tests/admin-app updates, apps/printer/AGENT.md operating manual - e2e: printing.spec.ts Co-authored-by: Stephan Charles <[email protected]> Co-authored-by: Amelia Hernandez <[email protected]> Co-authored-by: Markus Franz <[email protected]> Co-authored-by: Sabrina Hota <[email protected]> Co-authored-by: Nilüfer Doğan <[email protected]>
76 lines
2.4 KiB
Python
76 lines
2.4 KiB
Python
from __future__ import annotations
|
|
|
|
import httpx
|
|
import pytest
|
|
|
|
from conftest import FakePrinter, FakeRenderer, FakeRpc # noqa: F401 (path setup)
|
|
from worker.config import Config
|
|
from worker.main import Worker
|
|
from worker.rpc import InvalidToken, Rpc, RpcError, RpcUnavailable
|
|
|
|
CFG = Config(convivo_url="http://x", convivo_anon_key="k", station_token="t")
|
|
|
|
|
|
def make_rpc(handler) -> Rpc:
|
|
client = httpx.Client(transport=httpx.MockTransport(handler), headers={"apikey": "k"})
|
|
return Rpc(CFG, client=client)
|
|
|
|
|
|
def test_claim_rows_and_timeout():
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
assert request.url.path == "/rest/v1/rpc/printer_claim_badge_job"
|
|
return httpx.Response(200, json=[{"msg_id": 1, "read_ct": 1, "payload": {}}])
|
|
|
|
rows = make_rpc(handler).claim(10)
|
|
assert rows[0]["msg_id"] == 1
|
|
|
|
|
|
def test_claim_empty_returns_list():
|
|
rpc = make_rpc(lambda r: httpx.Response(200, json=[]))
|
|
assert rpc.claim(0) == []
|
|
|
|
|
|
def test_invalid_token_401():
|
|
rpc = make_rpc(lambda r: httpx.Response(401, json={"code": "28000"}))
|
|
with pytest.raises(InvalidToken):
|
|
rpc.complete(1)
|
|
|
|
|
|
def test_invalid_token_via_body_code():
|
|
rpc = make_rpc(lambda r: httpx.Response(400, json={"code": "28000", "message": "invalid printer token"}))
|
|
with pytest.raises(InvalidToken):
|
|
rpc.heartbeat({})
|
|
|
|
|
|
def test_5xx_is_unavailable():
|
|
rpc = make_rpc(lambda r: httpx.Response(503, text="nope"))
|
|
with pytest.raises(RpcUnavailable):
|
|
rpc.complete(1)
|
|
|
|
|
|
def test_connect_error_is_unavailable():
|
|
def handler(request: httpx.Request) -> httpx.Response:
|
|
raise httpx.ConnectError("boom", request=request)
|
|
|
|
rpc = make_rpc(handler)
|
|
with pytest.raises(RpcUnavailable):
|
|
rpc.claim(0)
|
|
|
|
|
|
def test_other_4xx_is_rpc_error():
|
|
rpc = make_rpc(lambda r: httpx.Response(400, json={"code": "P0001", "message": "job not found"}))
|
|
with pytest.raises(RpcError):
|
|
rpc.fail(1, "x")
|
|
|
|
|
|
def test_token_never_in_repr():
|
|
cfg = Config(convivo_url="http://x", convivo_anon_key="k", station_token="cvp_secret123")
|
|
rpc = Rpc(cfg, client=httpx.Client(transport=httpx.MockTransport(lambda r: httpx.Response(200, json=[]))))
|
|
assert "cvp_secret123" not in repr(cfg)
|
|
assert "cvp_secret123" not in repr(rpc)
|
|
|
|
|
|
def test_fail_returns_outcome_string():
|
|
rpc = make_rpc(lambda r: httpx.Response(200, json="dead_letter"))
|
|
assert rpc.fail(1, "err", retryable=False) == "dead_letter"
|