55 lines
1.7 KiB
Python
55 lines
1.7 KiB
Python
import json
|
|
import os
|
|
|
|
import pytest
|
|
|
|
from garmin.workout import GarminWorkoutCreator, StrengthWorkout, WorkoutStep
|
|
|
|
|
|
@pytest.fixture
|
|
def temp_workout_dir(tmp_path):
|
|
return str(tmp_path / "workouts")
|
|
|
|
def test_create_local_workout(temp_workout_dir):
|
|
creator = GarminWorkoutCreator(storage_dir=temp_workout_dir)
|
|
workout = StrengthWorkout(
|
|
name="Test Workout",
|
|
steps=[WorkoutStep(name="Bench Press", reps=10)]
|
|
)
|
|
|
|
path = creator.create_local_workout(workout)
|
|
assert os.path.exists(path)
|
|
|
|
with open(path, "r") as f:
|
|
data = json.load(f)
|
|
assert data["name"] == "Test Workout"
|
|
assert len(data["steps"]) == 1
|
|
|
|
def test_format_for_garmin():
|
|
creator = GarminWorkoutCreator()
|
|
workout = StrengthWorkout(
|
|
name="Test",
|
|
steps=[WorkoutStep(name="Squat", reps=15, rest_seconds=30)]
|
|
)
|
|
|
|
garmin_json = creator.format_for_garmin(workout)
|
|
assert garmin_json["workoutName"] == "Test"
|
|
# 1 exercise step + 1 rest step
|
|
assert len(garmin_json["workoutSteps"]) == 2
|
|
assert garmin_json["workoutSteps"][0]["endConditionValue"] == 15
|
|
assert garmin_json["workoutSteps"][1]["stepType"]["stepTypeKey"] == "rest"
|
|
assert garmin_json["workoutSteps"][1]["endConditionValue"] == 30
|
|
|
|
def test_load_local_workouts(temp_workout_dir):
|
|
os.makedirs(temp_workout_dir, exist_ok=True)
|
|
with open(os.path.join(temp_workout_dir, "test.json"), "w") as f:
|
|
f.write(json.dumps({
|
|
"name": "Stored Workout",
|
|
"steps": [{"name": "Pullup", "reps": 5}]
|
|
}))
|
|
|
|
creator = GarminWorkoutCreator(storage_dir=temp_workout_dir)
|
|
workouts = creator.load_local_workouts()
|
|
assert len(workouts) == 1
|
|
assert workouts[0].name == "Stored Workout"
|