Files
wodify-cli/tests/test_render.py
T
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

69 lines
2.1 KiB
Python

"""Rendering exists to keep output small. Verify shaping, not exact prose."""
from __future__ import annotations
from wodify import render
def test_flatten_html_turns_breaks_into_lines():
raw = "<p>For Time</p><p>30 Power Cleans<br>30 Toes-to-Bars</p>"
out = render.flatten_html(raw)
assert "For Time" in out
assert "30 Power Cleans" in out
assert "<" not in out
def test_flatten_html_unescapes_entities():
assert render.flatten_html("<p>135/95lb &amp; 24&quot;</p>") == '135/95lb & 24"'
def test_flatten_html_handles_none_and_empty():
assert render.flatten_html(None) == ""
assert render.flatten_html("") == ""
def test_flatten_html_collapses_runs_of_blank_lines():
assert "\n\n\n" not in render.flatten_html("a<br><br><br><br>b")
def test_find_all_reaches_nested_values():
data = {"a": {"b": [{"Description": "x"}, {"c": {"Description": "y"}}]}}
assert render.find_all(data, "Description") == ["x", "y"]
def test_first_list_skips_empty_lists():
data = {"p": {"List": []}, "q": {"List": [{"Id": 1}]}}
assert render.first_list(data) == [{"Id": 1}]
def test_bookings_reports_absence_rather_than_empty_string():
assert "No bookings" in render.bookings({"Response": {"List": []}})
def test_bookings_formats_rows():
data = {"Response": {"List": [
{"Class": {"StartDate": "2026-07-27", "StartTime": "5:30 PM",
"ClassName": "CrossFit: 5:30 PM"},
"StatusLabel": "Reserved"},
]}}
out = render.bookings(data)
assert "2026-07-27" in out and "CrossFit: 5:30 PM" in out and "[Reserved]" in out
def test_attendees_counts_and_lists():
data = {"Response": {"List": [{"Name": "A B"}, {"Name": "C D"}]}}
out = render.attendees(data)
assert out.startswith("2 attendees:") and "A B" in out and "C D" in out
def test_attendees_reports_absence():
assert "No attendees" in render.attendees({"Response": {"List": []}})
def test_workout_reports_absence():
assert "No workout content" in render.workout({"Response": {}})
def test_render_falls_back_to_json_for_unmapped_actions():
out = render.render("classdetail", {"Response": {"Id": 1}})
assert '"Id": 1' in out