The web server now runs a scheduler over schedules kept in SQLite
(~/.local/share/receipt-maker, outside the clone). A schedule is a
trigger, a receipt made of blocks, and options:
- Triggers: once, recurring (rrule-based, DST-safe), sun times,
reminders before calendar (ICS) events, RSS/JSON watchers, webhooks
with per-schedule secrets.
- Blocks, rendered fresh as one job: templated notes ({date},
{days_until:..}, rotating {choice}, trigger vars), QR, saved images,
random image, calendar agenda, feed headlines, dividers.
- Rules: quiet hours (hold/skip/ignore), daily cap, pause, catch-up
window for missed runs (never replayed), retries on connect failure
only; a mid-job drop (new PrinterDropped) is never resent.
receipt.py renders through composable Blocks (render_note/image/qr are
wrappers, output unchanged). Print history persists, with Print again.
The page moves to web/ with Print (note/image/QR + paper preview),
Schedules (presets, editor with live preview and next runs), History
and Settings tabs.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
89 lines
2.2 KiB
Python
89 lines
2.2 KiB
Python
"""Shared test fakes."""
|
|
|
|
import argparse
|
|
from pathlib import Path
|
|
|
|
from escpos import printer
|
|
|
|
import receipt
|
|
|
|
|
|
class FakePrinter:
|
|
"""Records the connection lifecycle and raw job payloads instead of talking to hardware."""
|
|
|
|
def __init__(self, fail_open=0, fail_raw=False):
|
|
self.calls = []
|
|
self.payloads = []
|
|
self.fail_open = fail_open # how many open() calls raise before one succeeds
|
|
self.fail_raw = fail_raw
|
|
|
|
def open(self):
|
|
self.calls.append("open")
|
|
if self.fail_open:
|
|
self.fail_open -= 1
|
|
raise OSError("no route to printer")
|
|
|
|
def _raw(self, data):
|
|
self.calls.append("raw")
|
|
if self.fail_raw:
|
|
raise OSError("connection reset")
|
|
self.payloads.append(data)
|
|
|
|
def close(self):
|
|
self.calls.append("close")
|
|
|
|
|
|
def escpos_bytes(build):
|
|
"""What the given escpos calls render to, for asserting on payloads."""
|
|
p = printer.Dummy(profile=receipt.PRINTER_PROFILE)
|
|
build(p)
|
|
return p.output
|
|
|
|
|
|
INIT = escpos_bytes(lambda p: p.hw("INIT"))
|
|
CUT = escpos_bytes(lambda p: p.cut())
|
|
|
|
|
|
def make_args(**overrides):
|
|
defaults = {
|
|
"usb": True, # avoids the network setup script in tests
|
|
"ip": "192.168.192.168",
|
|
"port": 9100,
|
|
"timestamp": False,
|
|
"message": None,
|
|
"name": None,
|
|
}
|
|
defaults.update(overrides)
|
|
return argparse.Namespace(**defaults)
|
|
|
|
|
|
FIXTURES = Path(__file__).parent / "fixtures"
|
|
CALENDAR_URL = "https://calendar.test/work.ics"
|
|
FEED_URL = "https://feed.test/rss.xml"
|
|
|
|
|
|
class FakeCache:
|
|
"""Stands in for receipt_sources.SourceCache: canned bodies by URL, no network."""
|
|
|
|
def __init__(self, bodies=None):
|
|
self.bodies = {
|
|
CALENDAR_URL: (FIXTURES / "calendar.ics").read_bytes(),
|
|
FEED_URL: (FIXTURES / "feed.xml").read_bytes(),
|
|
**(bodies or {}),
|
|
}
|
|
self.gets = []
|
|
|
|
def get(self, url, max_age):
|
|
from receipt_sources import SourceError
|
|
|
|
self.gets.append(url)
|
|
body = self.bodies.get(url)
|
|
if isinstance(body, Exception):
|
|
raise body
|
|
if body is None:
|
|
raise SourceError("couldn't connect")
|
|
return body
|
|
|
|
def forget(self, url):
|
|
pass
|