Add Doris Barbell live workout logger
This commit is contained in:
@@ -415,6 +415,108 @@ def test_seeded_routine_can_render_prefilled_log_sheet(tmp_path: Path) -> None:
|
||||
assert re.search(r'name="performed_at" value="\d{4}-\d{2}-\d{2}T\d{2}:\d{2}"', body)
|
||||
|
||||
|
||||
def test_seeded_routine_can_render_live_workout_page(tmp_path: Path) -> None:
|
||||
client = make_client(tmp_path)
|
||||
|
||||
summary = client.get('/api/dashboard/summary').json()
|
||||
shoulders = next(routine for routine in summary['routines'] if routine['name'] == 'Thursday: Shoulders')
|
||||
|
||||
response = client.get(f"/routines/{shoulders['id']}/live")
|
||||
|
||||
assert response.status_code == 200
|
||||
body = response.text
|
||||
assert 'Live workout logger' in body
|
||||
assert 'Log one exercise at a time' in body
|
||||
assert 'Start Thursday: Shoulders session' in body
|
||||
assert 'Resume live log' in client.get('/').text
|
||||
|
||||
|
||||
def test_live_workout_page_backfills_older_state_without_active_session_key(tmp_path: Path) -> None:
|
||||
client = make_client(tmp_path)
|
||||
|
||||
legacy_state = json.loads((tmp_path / 'state.json').read_text())
|
||||
legacy_state.pop('active_workout_sessions', None)
|
||||
(tmp_path / 'state.json').write_text(json.dumps(legacy_state))
|
||||
|
||||
response = client.get('/routines/seed-routine-04/live')
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'Start Thursday: Shoulders session' in response.text
|
||||
|
||||
|
||||
def test_live_workout_session_can_log_exercises_one_at_a_time_and_finish(tmp_path: Path) -> None:
|
||||
client = make_client(tmp_path)
|
||||
|
||||
summary = client.get('/api/dashboard/summary').json()
|
||||
shoulders = next(routine for routine in summary['routines'] if routine['name'] == 'Thursday: Shoulders')
|
||||
|
||||
start_response = client.post(
|
||||
f"/routines/{shoulders['id']}/live/start",
|
||||
data={
|
||||
'user_id': 'john',
|
||||
'performed_at': '2026-05-28T12:15:00',
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
assert start_response.status_code == 200
|
||||
start_body = start_response.text
|
||||
assert 'Session in progress' in start_body
|
||||
assert 'Logged exercises so far: 0' in start_body
|
||||
assert 'name="exercise_name"' in start_body
|
||||
assert 'name="set_0_reps"' in start_body
|
||||
assert 'name="set_0_weight_lbs"' in start_body
|
||||
|
||||
add_response = client.post(
|
||||
f"/routines/{shoulders['id']}/live/add-exercise",
|
||||
data={
|
||||
'user_id': 'john',
|
||||
'performed_at': '2026-05-28T12:15:00',
|
||||
'exercise_name': 'Shoulder Press',
|
||||
'set_count': '3',
|
||||
'set_0_reps': '10',
|
||||
'set_0_weight_lbs': '70',
|
||||
'set_1_reps': '10',
|
||||
'set_1_weight_lbs': '80',
|
||||
'set_2_reps': '8',
|
||||
'set_2_weight_lbs': '90',
|
||||
},
|
||||
follow_redirects=True,
|
||||
)
|
||||
|
||||
assert add_response.status_code == 200
|
||||
add_body = add_response.text
|
||||
assert 'Logged exercises so far: 1' in add_body
|
||||
assert 'Shoulder Press · 3 sets' in add_body
|
||||
assert 'Upright Row' in add_body
|
||||
|
||||
finish_response = client.post(
|
||||
f"/routines/{shoulders['id']}/live/finish",
|
||||
data={
|
||||
'user_id': 'john',
|
||||
'performed_at': '2026-05-28T12:15:00',
|
||||
'notes': 'Logged between sets.',
|
||||
},
|
||||
follow_redirects=False,
|
||||
)
|
||||
|
||||
assert finish_response.status_code == 303
|
||||
assert finish_response.headers['location'] == '/'
|
||||
|
||||
workout_history = client.get('/api/history/john/workouts')
|
||||
assert workout_history.status_code == 200
|
||||
payload = workout_history.json()
|
||||
assert payload[0]['routine_name'] == 'Thursday: Shoulders'
|
||||
assert payload[0]['exercise_count'] == 1
|
||||
assert payload[0]['set_count'] == 3
|
||||
assert payload[0]['notes'] == 'Logged between sets.'
|
||||
assert payload[0]['exercises'][0]['exercise_name'] == 'Shoulder Press'
|
||||
assert payload[0]['exercises'][0]['sets'][2] == {'reps': 8, 'weight_lbs': 90.0}
|
||||
|
||||
dashboard = client.get('/').text
|
||||
assert 'Resume Thursday: Shoulders live log' not in dashboard
|
||||
|
||||
|
||||
def test_seeded_routine_log_submission_creates_structured_workout(tmp_path: Path) -> None:
|
||||
client = make_client(tmp_path)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user