Files
wodify-cli/tests/test_attendees.py
lucioandClaude Opus 5 5a61890011 feat: read-only Wodify athlete client
A CLI that answers "what classes ran", "who was there" and "what was the
workout" with a single HTTP POST each -- no browser at query time.

Wodify's athlete app is an OutSystems Reactive SPA. Driving it with a headless
browser works but is slow and, for an LLM agent, expensive: a full page render
to read a few lines back out of the DOM. Its data actions are plain JSON
endpoints, so this talks to them directly.

  wodify list date 2026-07-25      time, coach, booked/max, title, duration, ID
  wodify list workout <id>         attendee names + that class's workout

Two phases. `prime` attaches over CDP to a browser that is already logged in and
captures the session cookies, the CSRF token, and each action's apiVersion and
body shape. Everything after that is stdlib HTTP -- the query path has no
third-party dependencies at all.

Three things genuinely require the browser, which is why priming exists:
- the session bearer nr1W_Theme_UI is HttpOnly, so it cannot be exported by hand
- X-CSRFToken is not in cookies, localStorage, or any JS global
- apiVersion is per-action, not global

Read-only is enforced in code, not by the credential (Wodify issues no
read-only token): an explicit allowlist plus a write-marker guard applied even
to allowlisted paths, so a careless registry edit fails closed. Tests assert
that real mutating endpoint names are refused.

Responses are cached in SQLite, keyed by the local date they were fetched on, so
a repeat query the same day touches no network. All fetching funnels through
service.py so a call site cannot forget the cache.

Staleness is explicit rather than silent: responses carry
hasModuleVersionChanged/hasApiVersionChanged, and the client raises
VersionStale/SessionExpired instead of returning a plausible empty result. That
matters because every bug found while building this produced confident wrong
output rather than an error -- see CLAUDE.md for the field-name traps.

History squashed before first publication: earlier commits embedded real gym
members' names in test fixtures. Fixtures now use fictional names.

122 tests, no network required.

Co-Authored-By: Claude Opus 5 <[email protected]>
2026-07-25 09:23:19 -07:00

117 lines
3.6 KiB
Python

"""Attendee parsing.
The name field is PersonName under Response.ClassDetailAttendee.List. An earlier
version looked for "Name", found nothing on a full class, and printed an invented
explanation about anonymous members -- a fabricated cause for its own bug. These
tests exist so that cannot recur.
"""
from __future__ import annotations
from wodify import render
def _att(name, status="Reserved", signed_in=False, no_show=False,
waitlisted=False, anonymous=False, rid=None):
return {
"PersonName": name,
"StatusInClass": status,
"HasReserved": True,
"HasSignedIn": signed_in,
"HasNoShow": no_show,
"isWaitlisted": waitlisted,
"IsAnonymous": anonymous,
"MemberSince": "2025-10-17",
"ClassReservationId": rid or f"res-{name}",
# Traps: nested zeros that must not be mistaken for the real fields.
"ClassId": "0",
"ProgramId": "0",
}
CLASS = {"Response": {"ClassDetailAttendee": {"List": [
_att("Alex Rivera"),
_att("Sam Okafor", status="Signed In", signed_in=True),
_att("Jordan Kim", no_show=True),
_att("Wanda Waits", waitlisted=True),
]}}}
def test_person_name_field_is_read():
"""Regression: reading "Name" yields nothing and looks like an empty class."""
names = render.attendee_names(CLASS)
assert "Alex Rivera" in names
assert len(names) == 4
def test_waitlisted_separated_from_roster():
out = render.attendee_block(CLASS)
assert "## Attendees — 3" in out, "waitlisted people are not attendees"
assert "Waitlist — 1" in out
assert "Wanda Waits" in out
def test_signed_in_marked():
assert "Sam Okafor [signed in]" in render.attendee_block(CLASS)
def test_no_show_marked():
out = render.attendee_block(CLASS)
assert "Jordan Kim" in out and "no-show" in out
def test_capacity_shown_when_supplied():
out = render.attendee_block(CLASS, booked=12, limit=12)
assert "of 12/12 booked" in out
def test_gap_between_booked_and_listed_is_flagged():
"""A class the account attended lists one fewer than booked; say so rather
than let it read as a miscount."""
out = render.attendee_block(CLASS, booked=4, limit=10) # 3 on roster + 1 waitlisted
assert "1 booked not listed" in out
def test_no_gap_note_when_counts_agree():
out = render.attendee_block(CLASS, booked=3, limit=10)
assert "not listed" not in out
def test_duplicate_reservations_deduplicated():
dupe = {"Response": {"ClassDetailAttendee": {"List": [
_att("Alex Rivera", rid="r1"), _att("Alex Rivera", rid="r1"),
]}}}
assert render.attendee_names(dupe) == ["Alex Rivera"]
def test_empty_list_does_not_invent_a_reason():
"""Say what is true -- nothing was returned -- and do not speculate why."""
out = render.attendee_block({"Response": {"ClassDetailAttendee": {"List": []}}})
assert "None returned" in out
assert "anonymous" not in out.lower()
def test_falls_back_to_first_last_name():
data = {"Response": {"ClassDetailAttendee": {"List": [
{"Firstname": "Pat", "LastName": "Doyle", "ClassReservationId": "r9"},
]}}}
assert render.attendee_names(data) == ["Pat Doyle"]
# --- duration ---------------------------------------------------------------
def test_duration_basic():
assert render.duration_minutes("17:30:00", "18:30:00") == 60
def test_duration_across_midnight():
assert render.duration_minutes("23:30:00", "00:30:00") == 60
def test_duration_unparseable_is_none():
assert render.duration_minutes("", "") is None
assert render.duration_minutes("bogus", "18:30:00") is None
def test_hhmm_trims_seconds():
assert render._hhmm("17:30:00") == "17:30"