From bdf556bf270cb7ce3ded106c90c959601e9e4dd9 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 24 Nov 2021 15:28:09 +0100 Subject: [PATCH] [API] tests - update workout fixtures --- .../tests/fixtures/fixtures_workouts.py | 37 +++++++++---------- fittrackee/tests/users/test_auth_api.py | 2 +- fittrackee/tests/users/test_users_api.py | 6 +-- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/fittrackee/tests/fixtures/fixtures_workouts.py b/fittrackee/tests/fixtures/fixtures_workouts.py index 5b2e142f..0f19b5f1 100644 --- a/fittrackee/tests/fixtures/fixtures_workouts.py +++ b/fittrackee/tests/fixtures/fixtures_workouts.py @@ -51,6 +51,14 @@ def sport_2_running() -> Sport: return sport +def update_workout(workout: Workout) -> None: + workout.ave_speed = float(workout.distance) / ( + workout.duration.seconds / 3600 + ) + workout.max_speed = workout.ave_speed + workout.moving = workout.duration + + @pytest.fixture() def workout_cycling_user_1() -> Workout: workout = Workout( @@ -60,9 +68,7 @@ def workout_cycling_user_1() -> Workout: distance=10, duration=datetime.timedelta(seconds=3600), ) - workout.max_speed = 10 - workout.ave_speed = 10 - workout.moving = workout.duration + update_workout(workout) db.session.add(workout) db.session.commit() return workout @@ -94,7 +100,7 @@ def workout_running_user_1() -> Workout: distance=12, duration=datetime.timedelta(seconds=6000), ) - workout.moving = workout.duration + update_workout(workout) db.session.add(workout) db.session.commit() return workout @@ -109,8 +115,7 @@ def seven_workouts_user_1() -> Workout: distance=5, duration=datetime.timedelta(seconds=1024), ) - workout.ave_speed = float(workout.distance) / (1024 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 120 workout.descent = 200 db.session.add(workout) @@ -123,8 +128,7 @@ def seven_workouts_user_1() -> Workout: distance=10, duration=datetime.timedelta(seconds=3456), ) - workout.ave_speed = float(workout.distance) / (3456 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 100 workout.descent = 80 db.session.add(workout) @@ -137,8 +141,7 @@ def seven_workouts_user_1() -> Workout: distance=10, duration=datetime.timedelta(seconds=1024), ) - workout.ave_speed = float(workout.distance) / (1024 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 80 workout.descent = 100 db.session.add(workout) @@ -151,8 +154,7 @@ def seven_workouts_user_1() -> Workout: distance=1, duration=datetime.timedelta(seconds=600), ) - workout.ave_speed = float(workout.distance) / (600 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 120 workout.descent = 180 db.session.add(workout) @@ -165,8 +167,7 @@ def seven_workouts_user_1() -> Workout: distance=10, duration=datetime.timedelta(seconds=1000), ) - workout.ave_speed = float(workout.distance) / (1000 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 100 workout.descent = 200 db.session.add(workout) @@ -179,8 +180,7 @@ def seven_workouts_user_1() -> Workout: distance=8, duration=datetime.timedelta(seconds=6000), ) - workout.ave_speed = float(workout.distance) / (6000 / 3600) - workout.moving = workout.duration + update_workout(workout) workout.ascent = 40 workout.descent = 20 db.session.add(workout) @@ -193,8 +193,7 @@ def seven_workouts_user_1() -> Workout: distance=10, duration=datetime.timedelta(seconds=3000), ) - workout.ave_speed = float(workout.distance) / (3000 / 3600) - workout.moving = workout.duration + update_workout(workout) db.session.add(workout) db.session.commit() return workout @@ -209,7 +208,7 @@ def workout_cycling_user_2() -> Workout: distance=15, duration=datetime.timedelta(seconds=3600), ) - workout.moving = workout.duration + update_workout(workout) db.session.add(workout) db.session.commit() return workout diff --git a/fittrackee/tests/users/test_auth_api.py b/fittrackee/tests/users/test_auth_api.py index ca3e8437..0f4d2819 100644 --- a/fittrackee/tests/users/test_auth_api.py +++ b/fittrackee/tests/users/test_auth_api.py @@ -558,7 +558,7 @@ class TestUserProfile(ApiTestCaseMixin): assert data['data']['imperial_units'] is False assert data['data']['nb_sports'] == 2 assert data['data']['nb_workouts'] == 2 - assert len(data['data']['records']) == 6 + assert len(data['data']['records']) == 8 assert data['data']['sports_list'] == [1, 2] assert data['data']['total_distance'] == 22 assert data['data']['total_duration'] == '2:40:00' diff --git a/fittrackee/tests/users/test_users_api.py b/fittrackee/tests/users/test_users_api.py index 371296de..d6c41b52 100644 --- a/fittrackee/tests/users/test_users_api.py +++ b/fittrackee/tests/users/test_users_api.py @@ -83,7 +83,7 @@ class TestGetUser(ApiTestCaseMixin): assert user['timezone'] is None assert user['weekm'] is False assert user['language'] is None - assert len(user['records']) == 6 + assert len(user['records']) == 8 assert user['nb_sports'] == 2 assert user['nb_workouts'] == 2 assert user['sports_list'] == [1, 2] @@ -206,7 +206,7 @@ class TestGetUsers(ApiTestCaseMixin): assert data['data']['users'][0]['weekm'] is False assert data['data']['users'][0]['nb_sports'] == 2 assert data['data']['users'][0]['nb_workouts'] == 2 - assert len(data['data']['users'][0]['records']) == 6 + assert len(data['data']['users'][0]['records']) == 8 assert data['data']['users'][0]['sports_list'] == [1, 2] assert data['data']['users'][0]['total_distance'] == 22.0 assert data['data']['users'][0]['total_duration'] == '2:40:00' @@ -215,7 +215,7 @@ class TestGetUsers(ApiTestCaseMixin): assert data['data']['users'][1]['weekm'] is False assert data['data']['users'][1]['nb_sports'] == 1 assert data['data']['users'][1]['nb_workouts'] == 1 - assert len(data['data']['users'][1]['records']) == 2 + assert len(data['data']['users'][1]['records']) == 4 assert data['data']['users'][1]['sports_list'] == [1] assert data['data']['users'][1]['total_distance'] == 15 assert data['data']['users'][1]['total_duration'] == '1:00:00'