"""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": "
Warm-Up
", "Comment": "2:00 Cardio
"},
{"Id": "2", "Name": "For Time", "Comment": "30 Power Cleans
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