Files
wodify-cli/tests/test_render_wod.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

76 lines
2.6 KiB
Python

"""Placeholder filtering is the subtle part: OutSystems returns a single zeroed
record for an empty result set, which reads exactly like real data."""
from __future__ import annotations
from wodify import render
def _wod_response(components):
return {"Classes": {"ProgramWODList": {"List": [
{"Id": "9001", "Name": "CGE8 2009 Remix", "Notes": "",
"WorkoutComponents": {"List": components}},
]}}}
EMPTY_PLACEHOLDER = {"Classes": {"ProgramWODList": {"List": [
{"Id": "0", "Date": "1900-01-01", "Name": "", "Comments": "",
"WorkoutComponents": {"List": []}},
]}}}
def test_placeholder_record_is_not_reported_as_content():
out = render.workout(EMPTY_PLACEHOLDER)
assert out.startswith("No workout content")
def test_real_records_filters_zero_ids():
rows = [{"Id": "0"}, {"Id": "12"}, {"Id": 0}, {"nope": 1}]
assert render._real_records(rows) == [{"Id": "12"}]
def test_workout_renders_title_and_components():
data = _wod_response([
{"Id": "1", "Name": "<p>Warm-Up</p>", "Comment": "<p>2:00 Cardio</p>"},
{"Id": "2", "Name": "For Time", "Comment": "30 Power Cleans<br>30 Box Jumps"},
])
out = render.workout(data)
assert "# CGE8 2009 Remix" in out
assert "Warm-Up" in out and "2:00 Cardio" in out
assert "30 Power Cleans" in out and "30 Box Jumps" in out
assert "<" not in out
def test_workout_skips_placeholder_components():
data = _wod_response([{"Id": "0", "Name": "", "Comment": ""}])
assert render.workout(data).startswith("# CGE8 2009 Remix")
def test_workout_deduplicates_identical_blocks():
data = _wod_response([
{"Id": "1", "Name": "For Time", "Comment": "30 Burpees"},
{"Id": "2", "Name": "For Time", "Comment": "30 Burpees"},
])
assert render.workout(data).count("30 Burpees") == 1
def test_classes_reports_absence_for_placeholder_only():
assert "No classes found" in render.classes(EMPTY_PLACEHOLDER)
def test_classes_lists_rows_with_capacity():
data = {"Schedules": {"ScheduleList": {"List": [
{"Id": "5", "ClassName": "CrossFit: 6:00 AM", "StartTime": "6:00am",
"ReservationCount": 5, "ClassLimit": 10},
]}}}
out = render.classes(data)
assert "CrossFit: 6:00 AM" in out and "5 | 10" in out
def test_classes_appends_wod_when_present():
data = _wod_response([{"Id": "1", "Name": "For Time", "Comment": "30 Burpees"}])
data["Schedules"] = {"ScheduleList": {"List": [
{"Id": "5", "ClassName": "CrossFit: 6:00 AM", "StartTime": "6:00am"},
]}}
out = render.classes(data)
assert "CrossFit: 6:00 AM" in out and "30 Burpees" in out