#!/usr/bin/env python3 """A stand-in for the church's ProPresenter, so no test can reach it. It serves exactly what the coordinator's adapter checks for: a message called "Parent Caller" with tokens Name and Room, a 204 on trigger, and a 204 on clear. Every trigger is appended to a log the test reads, which is how "sent to sanctuary" is verified without a sanctuary. """ import json, sys from http.server import BaseHTTPRequestHandler, HTTPServer UUID = "11111111-2222-3333-4444-555555555555" LOG = "/tmp/propresenter-mock.log" class Handler(BaseHTTPRequestHandler): def log_message(self, *args): pass def _json(self, body, code=200): payload = json.dumps(body).encode() self.send_response(code) self.send_header("Content-Type", "application/json") self.send_header("Content-Length", str(len(payload))) self.end_headers() self.wfile.write(payload) def do_GET(self): if self.path == "/version": return self._json({"name": "mock", "api_version": "v1"}) if self.path == "/v1/messages": return self._json([{ "id": {"name": "Parent Caller", "uuid": UUID}, "tokens": [{"name": "Name"}, {"name": "Room"}], }]) if self.path.endswith("/clear"): with open(LOG, "a") as fh: fh.write("CLEAR\n") self.send_response(204) self.end_headers() return self.send_response(404) self.end_headers() def do_POST(self): length = int(self.headers.get("Content-Length") or 0) body = self.rfile.read(length).decode() if self.path.endswith("/trigger"): with open(LOG, "a") as fh: fh.write("TRIGGER " + body + "\n") self.send_response(204) self.end_headers() return self.send_response(404) self.end_headers() if __name__ == "__main__": open(LOG, "w").close() HTTPServer(("127.0.0.1", int(sys.argv[1] if len(sys.argv) > 1 else 1025)), Handler).serve_forever()