feat(printer): badge print queue, Pi worker, captive-portal setup, admin printing view
- 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]>
This commit is contained in:
1 parent
0f3720d48a
commit
00c89c1b48
55 files changed
+7406
-29
No files matched your search
@@ -0,0 +1,74 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
from PIL import Image
|
||||
|
||||
from worker.label import LayoutTooLarge, compose, find_label
|
||||
|
||||
DIE_CUT = find_label("103x164")
|
||||
ENDLESS = find_label("103")
|
||||
|
||||
|
||||
def mm(px: int) -> float:
|
||||
return px * 25.4 / 300
|
||||
|
||||
|
||||
def badge_mm(w_mm: float, h_mm: float) -> Image.Image:
|
||||
return Image.new("RGB", (round(w_mm * 300 / 25.4), round(h_mm * 300 / 25.4)), "red")
|
||||
|
||||
|
||||
def test_label_specs():
|
||||
assert (DIE_CUT.width_px, DIE_CUT.height_px, DIE_CUT.die_cut) == (1200, 1822, True)
|
||||
assert (ENDLESS.width_px, ENDLESS.height_px, ENDLESS.die_cut) == (1200, 0, False)
|
||||
with pytest.raises(KeyError):
|
||||
find_label("nope")
|
||||
|
||||
|
||||
def test_die_cut_centers_badge():
|
||||
badge = badge_mm(100, 70)
|
||||
assert (badge.width, badge.height) == (1181, 827)
|
||||
out = compose(badge, DIE_CUT)
|
||||
assert out.size == (1200, 1822)
|
||||
assert out.getpixel((9, 497)) == (255, 0, 0)
|
||||
assert out.getpixel((0, 0)) == (255, 255, 255)
|
||||
assert out.getpixel((1199, 1821)) == (255, 255, 255)
|
||||
|
||||
|
||||
def test_endless_uses_badge_height():
|
||||
out = compose(badge_mm(100, 70), ENDLESS)
|
||||
assert out.size == (1200, 827)
|
||||
assert out.getpixel((9, 0)) == (255, 0, 0)
|
||||
assert out.getpixel((0, 0)) == (255, 255, 255)
|
||||
|
||||
|
||||
def test_rotated_when_it_only_fits_rotated():
|
||||
badge = badge_mm(150, 90)
|
||||
assert badge.width > DIE_CUT.width_px
|
||||
out = compose(badge, DIE_CUT)
|
||||
assert out.size == (1200, 1822)
|
||||
# Rotated 1063x1772 content is centered: margins 68/25 px.
|
||||
assert out.getpixel((600, 25)) == (255, 0, 0)
|
||||
assert out.getpixel((600, 0)) == (255, 255, 255)
|
||||
|
||||
|
||||
def test_too_large_raises():
|
||||
with pytest.raises(LayoutTooLarge) as err:
|
||||
compose(badge_mm(120, 200), DIE_CUT)
|
||||
message = str(err.value)
|
||||
assert "120x200 mm" in message and "103x164" in message
|
||||
|
||||
|
||||
def test_overshoot_is_cropped():
|
||||
out = compose(Image.new("RGB", (1203, 1822), "red"), DIE_CUT)
|
||||
assert out.size == (1200, 1822)
|
||||
|
||||
|
||||
def test_grayscale_input_converted():
|
||||
out = compose(Image.new("L", (1181, 827), 0), DIE_CUT)
|
||||
assert out.mode == "RGB"
|
||||
|
||||
|
||||
def test_compose_accepts_identifier_string():
|
||||
out = compose(badge_mm(100, 70), "103")
|
||||
assert mm(out.width) == pytest.approx(101.6, abs=0.1)
|
||||
assert out.height == 827
|
||||
Reference in new issue
Block a user