"""GetAllWorkoutData's real response shape, plus bookings range filtering. Shape taken from a live capture on 2026-07-25: the workout lives at Response.ResponseWOD.ResponseWorkout, not in ProgramWODList. """ from __future__ import annotations from wodify import render LIVE_SHAPE = { "Response": { "HasActiveMembership": True, "ErrorMessage": "", "ResponseWOD": { "WorkoutError": {"HasError": False, "ErrorMessage": ""}, "ResponseWorkout": { "Id": "25201299", "Date": "2026-07-25", "Name": "CrossFit - Sat, Jul 25", "Notes": "
Daily Coach's Brief
", "WorkoutComponents": {"List": [ {"Id": "123372298", "IsSection": True, "Name": "WARM-UP", "Comment": "General Warm-Up
2 x
15 Banded Good Mornings
"}, {"Id": "123372299", "IsSection": False, "Name": "091022 Games Mash-Up", "Comment": "7 Rounds
3 Wall Walks
"}, ]}, }, }, } } UNPOSTED = { "Response": { "ErrorMessage": "", "ResponseWOD": { "WorkoutError": {"HasError": False, "ErrorMessage": ""}, "ResponseWorkout": {"Id": "0", "Date": "1900-01-01", "Name": "", "Notes": "", "WorkoutComponents": {"List": []}}, }, } } def test_live_shape_renders_title_and_components(): out = render.workout(LIVE_SHAPE) assert out.startswith("# CrossFit - Sat, Jul 25") assert "## WARM-UP" in out, "IsSection components should be marked as sections" assert "15 Banded Good Mornings" in out assert "091022 Games Mash-Up" in out and "3 Wall Walks" in out assert "<" not in out def test_coach_brief_excluded_by_default(): """Notes runs to thousands of characters; keeping output small is the point.""" assert "Daily Coach's Brief" not in render.workout(LIVE_SHAPE) def test_coach_brief_included_on_request(): out = render.workout(LIVE_SHAPE, notes=True) assert "## Coach's brief" in out and "Daily Coach's Brief" in out def test_unposted_workout_is_reported_as_not_posted(): out = render.workout(UNPOSTED) assert "not posted" in out.lower() assert "# " not in out # --- bookings range filtering ------------------------------------------------- BOOKINGS = {"Response": {"List": [ {"Class": {"StartDate": "2026-07-20", "StartTime": "17:30:00", "ClassName": "CrossFit: 5:30 PM", "ClassId": "101"}, "StatusLabel": "Attended"}, {"Class": {"StartDate": "2026-07-22", "StartTime": "17:30:00", "ClassName": "CrossFit: 5:30 PM", "ClassId": "102"}, "StatusLabel": "Attended"}, {"Class": {"StartDate": "2026-07-27", "StartTime": "17:30:00", "ClassName": "CrossFit: 5:30 PM", "ClassId": "103"}, "StatusLabel": "Reserved"}, ]}} def test_booking_rows_are_sorted_and_expose_class_id(): rows = render.booking_rows(BOOKINGS) assert [r["date"] for r in rows] == ["2026-07-20", "2026-07-22", "2026-07-27"] assert rows[0]["class_id"] == "101" def test_bookings_since_filter(): out = render.bookings(BOOKINGS, since="2026-07-22") assert "2026-07-20" not in out and "2026-07-22" in out and "2026-07-27" in out def test_bookings_until_filter(): out = render.bookings(BOOKINGS, until="2026-07-22") assert "2026-07-27" not in out and "2026-07-20" in out def test_bookings_attended_only_excludes_future_reservations(): out = render.bookings(BOOKINGS, attended_only=True) assert "2026-07-27" not in out assert "2026-07-20" in out and "2026-07-22" in out def test_bookings_exposes_class_id_for_chaining(): """Requirement: list attended classes, then fetch each one's workout.""" assert "class_id=101" in render.bookings(BOOKINGS) def test_empty_filter_result_reports_pre_filter_count(): out = render.bookings(BOOKINGS, since="2030-01-01") assert "No bookings found" in out and "3 returned before filtering" in out