nomadro/deploy/coffee/_smoke_local.py
Eric ffa456afdf Ship social join profile + SeaweedFS avatars, notify/coffee, and .com audience stack.
Pay-then-profile join desk with live card, S3 upload fallback, hydration-safe drafts; document on test9 README.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-04 02:25:05 +08:00

61 lines
1.8 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import urllib.request
from datetime import date, timedelta
BASE = "http://127.0.0.1:8024/api/coffee/v1"
def req(method: str, path: str, body=None):
data = None if body is None else json.dumps(body).encode()
r = urllib.request.Request(
BASE + path,
data=data,
method=method,
headers={"Content-Type": "application/json"} if body is not None else {},
)
with urllib.request.urlopen(r, timeout=10) as res:
return json.loads(res.read().decode())
def main() -> int:
print("hosts", [h["username"] for h in req("GET", "/hosts")["hosts"]])
h = req("GET", "/hosts/alice")["host"]
print("alice events", [e["slug"] for e in h["event_types"]])
day = None
slot = None
for i in range(0, 10):
d = (date.today() + timedelta(days=i)).isoformat()
s = req("GET", f"/hosts/alice/event-types/coffee-30/slots?day={d}")
if s["slots"]:
day = d
slot = s["slots"][0]
break
print("day", day, "slot", slot)
assert day and slot
bk = req(
"POST",
"/bookings",
{
"username": "alice",
"event_slug": "coffee-30",
"start": slot["start"],
"attendee_name": "Smoke Tester",
"attendee_email": "smoke@nomadro.com",
"notes": "cal secondary-dev",
},
)
print("booked", bk["booking"]["id"], bk["booking"]["status"])
s2 = req("GET", f"/hosts/alice/event-types/coffee-30/slots?day={day}")
assert slot["start"] not in {x["start"] for x in s2["slots"]}
print("slot_removed_ok")
c = req("POST", f"/bookings/{bk['booking']['id']}/cancel")
print("cancel", c["booking"]["status"])
print("OK")
return 0
if __name__ == "__main__":
raise SystemExit(main())