"""Schedule parsing. Shape from a live capture 2026-07-25: Response.ResponseClassList.Class.List. Two bugs are pinned here because both produced plausible-looking wrong output rather than an error. """ from __future__ import annotations from wodify import render # Abridged real row. GroupMemberReservationStatus.ClassId == "0" is the trap: # flattening nested dicts up clobbers the real Id and collapses every class # into a single row. def _row(cid, name, start, program, booked, coach): return { "Id": cid, "Name": name, "StartTime": start, "EndTime": "13:00:00", "StartDate": "2026-07-20", "ProgramId": program, "ClassLimit": 10, "ReservationCount": booked, "WaitlistCount": 0, "Status": "", "Coaches": {"List": [{"Name": coach, "Id": "5706147"}]}, "GroupMemberReservationStatus": {"ClassId": "0", "IsSignedIn": {"List": []}}, } DAY = {"Response": {"ResponseClassList": {"Class": {"List": [ _row("190917816", "CrossFit: 5:30 PM", "17:30:00", "133059", 9, "Pat Doyle"), _row("190917671", "CrossFit: 12:00 PM", "12:00:00", "133059", 10, "Chris Nolan"), _row("190918133", "CrossFit Pump: 6:30 PM", "18:30:00", "131311", 7, "Pat Doyle"), ]}}}} def test_all_classes_are_returned_not_collapsed(): """Regression: nested ClassId "0" previously collapsed all rows into one.""" rows = render.class_rows(DAY) assert len(rows) == 3 assert [r["class_id"] for r in rows] == ["190917671", "190917816", "190918133"] def test_rows_sorted_by_start_time(): assert [r["start"] for r in render.class_rows(DAY)] == \ ["12:00:00", "17:30:00", "18:30:00"] def test_real_id_survives_nested_class_id_zero(): row = render.class_rows(DAY)[1] assert row["class_id"] == "190917816" assert row["class_id"] != "0" def test_coach_extracted_from_nested_list(): by_id = {r["class_id"]: r for r in render.class_rows(DAY)} assert by_id["190917671"]["coach"] == "Chris Nolan" assert by_id["190918133"]["coach"] == "Pat Doyle" def test_program_ids_distinguish_workouts(): """Classes in different programs have different WODs, so program_id must survive -- reporting one program's workout for another is a wrong answer.""" programs = {r["program_id"] for r in render.class_rows(DAY)} assert programs == {"133059", "131311"} def test_missing_coach_list_does_not_crash(): row = _row("1", "X", "06:00:00", "133059", 1, "Y") row["Coaches"] = {"List": []} assert render.class_rows({"Class": {"List": [row]}})[0]["coach"] == "" def test_placeholder_rows_dropped(): day = {"Class": {"List": [_row("0", "", "00:00:00", "0", 0, "")]}} assert render.class_rows(day) == [] def test_classes_render_includes_capacity_coach_and_id(): out = render.classes(DAY) assert "CrossFit: 5:30 PM" in out assert "9 | 10" in out assert "coach=Pat Doyle" in out assert "class_id=190917816" in out assert out.count("\n- ") + 1 == 3, "all three classes should be listed" # --- own-reservation highlighting -------------------------------------------- # The schedule row's Status field carries the account's relationship to the # class ("Signed In", "Reserved", "" for none). Verified live 2026-07-25. def _day_with_status(): day = {"Response": {"ResponseClassList": {"Class": {"List": [ _row("1", "CrossFit: 12:00 PM", "12:00:00", "133059", 10, "Chris Nolan"), _row("2", "CrossFit: 5:30 PM", "17:30:00", "133059", 9, "Pat Doyle"), ]}}}} day["Response"]["ResponseClassList"]["Class"]["List"][1]["Status"] = "Signed In" return day def test_class_rows_carry_own_status(): rows = render.class_rows(_day_with_status()) assert rows[0]["status"] == "" assert rows[1]["status"] == "Signed In" def test_day_table_marks_own_class(): out = render.day_table(render.class_rows(_day_with_status()), "2026-07-24") marked = [l for l in out.splitlines() if l.startswith("»")] assert len(marked) == 1 assert "CrossFit: 5:30 PM" in marked[0] and "signed in" in marked[0] def test_day_table_unrelated_class_not_marked(): out = render.day_table(render.class_rows(_day_with_status()), "2026-07-24") noon = next(l for l in out.splitlines() if "12:00 PM" in l) assert not noon.startswith("»") assert "signed in" not in noon def test_classes_renderer_marks_own_class(): out = render.classes(_day_with_status()) assert "«you: signed in»" in out assert out.count("«you:") == 1