API - replace 'Activity' with 'Workout' - #58
This commit is contained in:
@ -1,75 +0,0 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.activities.utils_id import decode_short_id
|
||||
from fittrackee.users.models import User
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestActivityModel:
|
||||
def test_activity_model(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
activity_cycling_user_1: Activity,
|
||||
) -> None:
|
||||
activity_cycling_user_1.title = 'Test'
|
||||
|
||||
assert 1 == activity_cycling_user_1.id
|
||||
assert activity_cycling_user_1.uuid is not None
|
||||
assert 1 == activity_cycling_user_1.user_id
|
||||
assert 1 == activity_cycling_user_1.sport_id
|
||||
assert '2018-01-01 00:00:00' == str(
|
||||
activity_cycling_user_1.activity_date
|
||||
)
|
||||
assert 10.0 == float(activity_cycling_user_1.distance)
|
||||
assert '1:00:00' == str(activity_cycling_user_1.duration)
|
||||
assert 'Test' == activity_cycling_user_1.title
|
||||
assert '<Activity \'Cycling\' - 2018-01-01 00:00:00>' == str(
|
||||
activity_cycling_user_1
|
||||
)
|
||||
|
||||
serialized_activity = activity_cycling_user_1.serialize()
|
||||
assert isinstance(decode_short_id(serialized_activity['id']), UUID)
|
||||
assert 'test' == serialized_activity['user']
|
||||
assert 1 == serialized_activity['sport_id']
|
||||
assert serialized_activity['title'] == 'Test'
|
||||
assert 'creation_date' in serialized_activity
|
||||
assert serialized_activity['modification_date'] is not None
|
||||
assert (
|
||||
str(serialized_activity['activity_date']) == '2018-01-01 00:00:00'
|
||||
)
|
||||
assert serialized_activity['duration'] == '1:00:00'
|
||||
assert serialized_activity['pauses'] is None
|
||||
assert serialized_activity['moving'] == '1:00:00'
|
||||
assert serialized_activity['distance'] == 10.0
|
||||
assert serialized_activity['max_alt'] is None
|
||||
assert serialized_activity['descent'] is None
|
||||
assert serialized_activity['ascent'] is None
|
||||
assert serialized_activity['max_speed'] == 10.0
|
||||
assert serialized_activity['ave_speed'] == 10.0
|
||||
assert serialized_activity['with_gpx'] is False
|
||||
assert serialized_activity['bounds'] == []
|
||||
assert serialized_activity['previous_activity'] is None
|
||||
assert serialized_activity['next_activity'] is None
|
||||
assert serialized_activity['segments'] == []
|
||||
assert serialized_activity['records'] != []
|
||||
assert serialized_activity['map'] is None
|
||||
assert serialized_activity['weather_start'] is None
|
||||
assert serialized_activity['weather_end'] is None
|
||||
assert serialized_activity['notes'] is None
|
||||
|
||||
def test_activity_segment_model(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_cycling_user_1_segment: Activity,
|
||||
) -> None:
|
||||
assert (
|
||||
f'<Segment \'{activity_cycling_user_1_segment.segment_id}\' '
|
||||
f'for activity \'{activity_cycling_user_1.short_id}\'>'
|
||||
== str(activity_cycling_user_1_segment)
|
||||
)
|
@ -4,10 +4,10 @@ from typing import Generator, Optional
|
||||
|
||||
import pytest
|
||||
from fittrackee import create_app, db
|
||||
from fittrackee.activities.models import Activity, ActivitySegment, Sport
|
||||
from fittrackee.application.models import AppConfig
|
||||
from fittrackee.application.utils import update_app_config_from_database
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout, WorkoutSegment
|
||||
|
||||
os.environ['FLASK_ENV'] = 'testing'
|
||||
os.environ['APP_SETTINGS'] = 'fittrackee.config.TestingConfig'
|
||||
@ -180,149 +180,149 @@ def sport_2_running() -> Sport:
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def activity_cycling_user_1() -> Activity:
|
||||
activity = Activity(
|
||||
def workout_cycling_user_1() -> Workout:
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('01/01/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('01/01/2018', '%d/%m/%Y'),
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=3600),
|
||||
)
|
||||
activity.max_speed = 10
|
||||
activity.ave_speed = 10
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.max_speed = 10
|
||||
workout.ave_speed = 10
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.commit()
|
||||
return activity
|
||||
return workout
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def activity_cycling_user_1_segment(
|
||||
activity_cycling_user_1: Activity,
|
||||
) -> ActivitySegment:
|
||||
activity_segment = ActivitySegment(
|
||||
activity_id=activity_cycling_user_1.id,
|
||||
activity_uuid=activity_cycling_user_1.uuid,
|
||||
def workout_cycling_user_1_segment(
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> WorkoutSegment:
|
||||
workout_segment = WorkoutSegment(
|
||||
workout_id=workout_cycling_user_1.id,
|
||||
workout_uuid=workout_cycling_user_1.uuid,
|
||||
segment_id=0,
|
||||
)
|
||||
activity_segment.duration = datetime.timedelta(seconds=6000)
|
||||
activity_segment.moving = activity_segment.duration
|
||||
activity_segment.distance = 5
|
||||
db.session.add(activity_segment)
|
||||
workout_segment.duration = datetime.timedelta(seconds=6000)
|
||||
workout_segment.moving = workout_segment.duration
|
||||
workout_segment.distance = 5
|
||||
db.session.add(workout_segment)
|
||||
db.session.commit()
|
||||
return activity_segment
|
||||
return workout_segment
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def activity_running_user_1() -> Activity:
|
||||
activity = Activity(
|
||||
def workout_running_user_1() -> Workout:
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=2,
|
||||
activity_date=datetime.datetime.strptime('01/04/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('01/04/2018', '%d/%m/%Y'),
|
||||
distance=12,
|
||||
duration=datetime.timedelta(seconds=6000),
|
||||
)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.commit()
|
||||
return activity
|
||||
return workout
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def seven_activities_user_1() -> Activity:
|
||||
activity = Activity(
|
||||
def seven_workouts_user_1() -> Workout:
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('20/03/2017', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('20/03/2017', '%d/%m/%Y'),
|
||||
distance=5,
|
||||
duration=datetime.timedelta(seconds=1024),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (1024 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (1024 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('01/06/2017', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('01/06/2017', '%d/%m/%Y'),
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=3456),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (3456 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (3456 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('01/01/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('01/01/2018', '%d/%m/%Y'),
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=1024),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (1024 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (1024 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('23/02/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('23/02/2018', '%d/%m/%Y'),
|
||||
distance=1,
|
||||
duration=datetime.timedelta(seconds=600),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (600 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (600 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('23/02/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('23/02/2018', '%d/%m/%Y'),
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=1000),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (1000 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (1000 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('01/04/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('01/04/2018', '%d/%m/%Y'),
|
||||
distance=8,
|
||||
duration=datetime.timedelta(seconds=6000),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (6000 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (6000 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.flush()
|
||||
activity = Activity(
|
||||
workout = Workout(
|
||||
user_id=1,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('09/05/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('09/05/2018', '%d/%m/%Y'),
|
||||
distance=10,
|
||||
duration=datetime.timedelta(seconds=3000),
|
||||
)
|
||||
activity.ave_speed = float(activity.distance) / (3000 / 3600)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.ave_speed = float(workout.distance) / (3000 / 3600)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.commit()
|
||||
return activity
|
||||
return workout
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def activity_cycling_user_2() -> Activity:
|
||||
activity = Activity(
|
||||
def workout_cycling_user_2() -> Workout:
|
||||
workout = Workout(
|
||||
user_id=2,
|
||||
sport_id=1,
|
||||
activity_date=datetime.datetime.strptime('23/01/2018', '%d/%m/%Y'),
|
||||
workout_date=datetime.datetime.strptime('23/01/2018', '%d/%m/%Y'),
|
||||
distance=15,
|
||||
duration=datetime.timedelta(seconds=3600),
|
||||
)
|
||||
activity.moving = activity.duration
|
||||
db.session.add(activity)
|
||||
workout.moving = workout.duration
|
||||
db.session.add(workout)
|
||||
db.session.commit()
|
||||
return activity
|
||||
return workout
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
@ -332,7 +332,7 @@ def gpx_file() -> str:
|
||||
'<gpx xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxext="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns="http://www.topografix.com/GPX/1/1">' # noqa
|
||||
' <metadata/>'
|
||||
' <trk>'
|
||||
' <name>just an activity</name>'
|
||||
' <name>just a workout</name>'
|
||||
' <trkseg>'
|
||||
' <trkpt lat="44.68095" lon="6.07367">'
|
||||
' <ele>998</ele>'
|
||||
@ -580,7 +580,7 @@ def gpx_file_with_segments() -> str:
|
||||
'<gpx xmlns:gpxdata="http://www.cluetrust.com/XML/GPXDATA/1/0" xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1" xmlns:gpxext="http://www.garmin.com/xmlschemas/GpxExtensions/v3" xmlns="http://www.topografix.com/GPX/1/1">' # noqa
|
||||
' <metadata/>'
|
||||
' <trk>'
|
||||
' <name>just an activity</name>'
|
||||
' <name>just a workout</name>'
|
||||
' <trkseg>'
|
||||
' <trkpt lat="44.68095" lon="6.07367">'
|
||||
' <ele>998</ele>'
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -3,9 +3,9 @@ from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.users.utils_token import get_user_token
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
from freezegun import freeze_time
|
||||
|
||||
@ -446,8 +446,8 @@ class TestUserProfile:
|
||||
assert data['data']['timezone'] is None
|
||||
assert data['data']['weekm'] is False
|
||||
assert data['data']['language'] is None
|
||||
assert data['data']['nb_activities'] == 0
|
||||
assert data['data']['nb_sports'] == 0
|
||||
assert data['data']['nb_workouts'] == 0
|
||||
assert data['data']['sports_list'] == []
|
||||
assert data['data']['total_distance'] == 0
|
||||
assert data['data']['total_duration'] == '0:00:00'
|
||||
@ -484,21 +484,21 @@ class TestUserProfile:
|
||||
assert data['data']['timezone'] == 'America/New_York'
|
||||
assert data['data']['weekm'] is False
|
||||
assert data['data']['language'] == 'en'
|
||||
assert data['data']['nb_activities'] == 0
|
||||
assert data['data']['nb_sports'] == 0
|
||||
assert data['data']['nb_workouts'] == 0
|
||||
assert data['data']['sports_list'] == []
|
||||
assert data['data']['total_distance'] == 0
|
||||
assert data['data']['total_duration'] == '0:00:00'
|
||||
assert response.status_code == 200
|
||||
|
||||
def test_it_returns_user_profile_with_activities(
|
||||
def test_it_returns_user_profile_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -521,8 +521,8 @@ class TestUserProfile:
|
||||
assert data['data']['created_at']
|
||||
assert not data['data']['admin']
|
||||
assert data['data']['timezone'] is None
|
||||
assert data['data']['nb_activities'] == 2
|
||||
assert data['data']['nb_sports'] == 2
|
||||
assert data['data']['nb_workouts'] == 2
|
||||
assert data['data']['sports_list'] == [1, 2]
|
||||
assert data['data']['total_distance'] == 22
|
||||
assert data['data']['total_duration'] == '2:40:00'
|
||||
@ -585,8 +585,8 @@ class TestUserProfileUpdate:
|
||||
assert data['data']['timezone'] == 'America/New_York'
|
||||
assert data['data']['weekm'] is True
|
||||
assert data['data']['language'] == 'fr'
|
||||
assert data['data']['nb_activities'] == 0
|
||||
assert data['data']['nb_sports'] == 0
|
||||
assert data['data']['nb_workouts'] == 0
|
||||
assert data['data']['sports_list'] == []
|
||||
assert data['data']['total_distance'] == 0
|
||||
assert data['data']['total_duration'] == '0:00:00'
|
||||
@ -636,8 +636,8 @@ class TestUserProfileUpdate:
|
||||
assert data['data']['timezone'] == 'America/New_York'
|
||||
assert data['data']['weekm'] is True
|
||||
assert data['data']['language'] == 'fr'
|
||||
assert data['data']['nb_activities'] == 0
|
||||
assert data['data']['nb_sports'] == 0
|
||||
assert data['data']['nb_workouts'] == 0
|
||||
assert data['data']['sports_list'] == []
|
||||
assert data['data']['total_distance'] == 0
|
||||
assert data['data']['total_duration'] == '0:00:00'
|
||||
|
@ -3,13 +3,13 @@ from datetime import datetime, timedelta
|
||||
from io import BytesIO
|
||||
from unittest.mock import patch
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestGetUser:
|
||||
def test_it_gets_single_user_without_activities(
|
||||
def test_it_gets_single_user_without_workouts(
|
||||
self, app: Flask, user_1: User, user_2: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -45,20 +45,20 @@ class TestGetUser:
|
||||
assert user['timezone'] is None
|
||||
assert user['weekm'] is False
|
||||
assert user['language'] is None
|
||||
assert user['nb_activities'] == 0
|
||||
assert user['nb_sports'] == 0
|
||||
assert user['nb_workouts'] == 0
|
||||
assert user['sports_list'] == []
|
||||
assert user['total_distance'] == 0
|
||||
assert user['total_duration'] == '0:00:00'
|
||||
|
||||
def test_it_gets_single_user_with_activities(
|
||||
def test_it_gets_single_user_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -93,8 +93,8 @@ class TestGetUser:
|
||||
assert user['timezone'] is None
|
||||
assert user['weekm'] is False
|
||||
assert user['language'] is None
|
||||
assert user['nb_activities'] == 2
|
||||
assert user['nb_sports'] == 2
|
||||
assert user['nb_workouts'] == 2
|
||||
assert user['sports_list'] == [1, 2]
|
||||
assert user['total_distance'] == 22
|
||||
assert user['total_duration'] == '2:40:00'
|
||||
@ -158,24 +158,24 @@ class TestGetUsers:
|
||||
assert data['data']['users'][0]['timezone'] is None
|
||||
assert data['data']['users'][0]['weekm'] is False
|
||||
assert data['data']['users'][0]['language'] is None
|
||||
assert data['data']['users'][0]['nb_activities'] == 0
|
||||
assert data['data']['users'][0]['nb_sports'] == 0
|
||||
assert data['data']['users'][0]['nb_workouts'] == 0
|
||||
assert data['data']['users'][0]['sports_list'] == []
|
||||
assert data['data']['users'][0]['total_distance'] == 0
|
||||
assert data['data']['users'][0]['total_duration'] == '0:00:00'
|
||||
assert data['data']['users'][1]['timezone'] is None
|
||||
assert data['data']['users'][1]['weekm'] is False
|
||||
assert data['data']['users'][1]['language'] is None
|
||||
assert data['data']['users'][1]['nb_activities'] == 0
|
||||
assert data['data']['users'][1]['nb_sports'] == 0
|
||||
assert data['data']['users'][1]['nb_workouts'] == 0
|
||||
assert data['data']['users'][1]['sports_list'] == []
|
||||
assert data['data']['users'][1]['total_distance'] == 0
|
||||
assert data['data']['users'][1]['total_duration'] == '0:00:00'
|
||||
assert data['data']['users'][2]['timezone'] is None
|
||||
assert data['data']['users'][2]['weekm'] is True
|
||||
assert data['data']['users'][2]['language'] is None
|
||||
assert data['data']['users'][2]['nb_activities'] == 0
|
||||
assert data['data']['users'][2]['nb_sports'] == 0
|
||||
assert data['data']['users'][2]['nb_workouts'] == 0
|
||||
assert data['data']['users'][2]['sports_list'] == []
|
||||
assert data['data']['users'][2]['total_distance'] == 0
|
||||
assert data['data']['users'][2]['total_duration'] == '0:00:00'
|
||||
@ -187,17 +187,17 @@ class TestGetUsers:
|
||||
'total': 3,
|
||||
}
|
||||
|
||||
def test_it_gets_users_list_with_activities(
|
||||
def test_it_gets_users_list_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
sport_2_running: Sport,
|
||||
activity_running_user_1: Activity,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_running_user_1: Workout,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -229,22 +229,22 @@ class TestGetUsers:
|
||||
assert 'sam@test.com' in data['data']['users'][2]['email']
|
||||
assert data['data']['users'][0]['timezone'] is None
|
||||
assert data['data']['users'][0]['weekm'] is False
|
||||
assert data['data']['users'][0]['nb_activities'] == 2
|
||||
assert data['data']['users'][0]['nb_sports'] == 2
|
||||
assert data['data']['users'][0]['nb_workouts'] == 2
|
||||
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'
|
||||
assert data['data']['users'][1]['timezone'] is None
|
||||
assert data['data']['users'][1]['weekm'] is False
|
||||
assert data['data']['users'][1]['nb_activities'] == 1
|
||||
assert data['data']['users'][1]['nb_sports'] == 1
|
||||
assert data['data']['users'][1]['nb_workouts'] == 1
|
||||
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'
|
||||
assert data['data']['users'][2]['timezone'] is None
|
||||
assert data['data']['users'][2]['weekm'] is True
|
||||
assert data['data']['users'][2]['nb_activities'] == 0
|
||||
assert data['data']['users'][2]['nb_sports'] == 0
|
||||
assert data['data']['users'][2]['nb_workouts'] == 0
|
||||
assert data['data']['users'][2]['sports_list'] == []
|
||||
assert data['data']['users'][2]['total_distance'] == 0
|
||||
assert data['data']['users'][2]['total_duration'] == '0:00:00'
|
||||
@ -745,14 +745,14 @@ class TestGetUsers:
|
||||
'total': 3,
|
||||
}
|
||||
|
||||
def test_it_gets_users_list_ordered_by_activities_count(
|
||||
def test_it_gets_users_list_ordered_by_workouts_count(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -762,7 +762,7 @@ class TestGetUsers:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/users?order_by=activities_count',
|
||||
'/api/users?order_by=workouts_count',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -774,11 +774,11 @@ class TestGetUsers:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['users']) == 3
|
||||
assert 'test' in data['data']['users'][0]['username']
|
||||
assert 0 == data['data']['users'][0]['nb_activities']
|
||||
assert 0 == data['data']['users'][0]['nb_workouts']
|
||||
assert 'sam' in data['data']['users'][1]['username']
|
||||
assert 0 == data['data']['users'][1]['nb_activities']
|
||||
assert 0 == data['data']['users'][1]['nb_workouts']
|
||||
assert 'toto' in data['data']['users'][2]['username']
|
||||
assert 1 == data['data']['users'][2]['nb_activities']
|
||||
assert 1 == data['data']['users'][2]['nb_workouts']
|
||||
assert data['pagination'] == {
|
||||
'has_next': False,
|
||||
'has_prev': False,
|
||||
@ -787,14 +787,14 @@ class TestGetUsers:
|
||||
'total': 3,
|
||||
}
|
||||
|
||||
def test_it_gets_users_list_ordered_by_activities_count_ascending(
|
||||
def test_it_gets_users_list_ordered_by_workouts_count_ascending(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -804,7 +804,7 @@ class TestGetUsers:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/users?order_by=activities_count&order=asc',
|
||||
'/api/users?order_by=workouts_count&order=asc',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -816,11 +816,11 @@ class TestGetUsers:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['users']) == 3
|
||||
assert 'test' in data['data']['users'][0]['username']
|
||||
assert 0 == data['data']['users'][0]['nb_activities']
|
||||
assert 0 == data['data']['users'][0]['nb_workouts']
|
||||
assert 'sam' in data['data']['users'][1]['username']
|
||||
assert 0 == data['data']['users'][1]['nb_activities']
|
||||
assert 0 == data['data']['users'][1]['nb_workouts']
|
||||
assert 'toto' in data['data']['users'][2]['username']
|
||||
assert 1 == data['data']['users'][2]['nb_activities']
|
||||
assert 1 == data['data']['users'][2]['nb_workouts']
|
||||
assert data['pagination'] == {
|
||||
'has_next': False,
|
||||
'has_prev': False,
|
||||
@ -829,14 +829,14 @@ class TestGetUsers:
|
||||
'total': 3,
|
||||
}
|
||||
|
||||
def test_it_gets_users_list_ordered_by_activities_count_descending(
|
||||
def test_it_gets_users_list_ordered_by_workouts_count_descending(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -846,7 +846,7 @@ class TestGetUsers:
|
||||
)
|
||||
|
||||
response = client.get(
|
||||
'/api/users?order_by=activities_count&order=desc',
|
||||
'/api/users?order_by=workouts_count&order=desc',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -858,11 +858,11 @@ class TestGetUsers:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['users']) == 3
|
||||
assert 'toto' in data['data']['users'][0]['username']
|
||||
assert 1 == data['data']['users'][0]['nb_activities']
|
||||
assert 1 == data['data']['users'][0]['nb_workouts']
|
||||
assert 'test' in data['data']['users'][1]['username']
|
||||
assert 0 == data['data']['users'][1]['nb_activities']
|
||||
assert 0 == data['data']['users'][1]['nb_workouts']
|
||||
assert 'sam' in data['data']['users'][2]['username']
|
||||
assert 0 == data['data']['users'][2]['nb_activities']
|
||||
assert 0 == data['data']['users'][2]['nb_workouts']
|
||||
assert data['pagination'] == {
|
||||
'has_next': False,
|
||||
'has_prev': False,
|
||||
@ -1156,7 +1156,7 @@ class TestDeleteUser:
|
||||
|
||||
assert response.status_code == 204
|
||||
|
||||
def test_user_with_activity_can_delete_its_own_account(
|
||||
def test_user_with_workout_can_delete_its_own_account(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -1166,7 +1166,7 @@ class TestDeleteUser:
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities',
|
||||
'/api/workouts',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
|
@ -19,8 +19,8 @@ class TestUserModel:
|
||||
assert serialized_user['timezone'] is None
|
||||
assert serialized_user['weekm'] is False
|
||||
assert serialized_user['language'] is None
|
||||
assert serialized_user['nb_activities'] == 0
|
||||
assert serialized_user['nb_sports'] == 0
|
||||
assert serialized_user['nb_workouts'] == 0
|
||||
assert serialized_user['total_distance'] == 0
|
||||
assert serialized_user['total_duration'] == '0:00:00'
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
@ -13,8 +13,8 @@ class TestGetRecords:
|
||||
user_2: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -37,64 +37,64 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][0]['activity_id']
|
||||
workout_cycling_user_1.short_id
|
||||
== data['data']['records'][0]['workout_id']
|
||||
)
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 'value' in data['data']['records'][0]
|
||||
|
||||
assert (
|
||||
'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][1]['activity_id']
|
||||
workout_cycling_user_1.short_id
|
||||
== data['data']['records'][1]['workout_id']
|
||||
)
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 'value' in data['data']['records'][1]
|
||||
|
||||
assert (
|
||||
'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
)
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][2]['activity_id']
|
||||
workout_cycling_user_1.short_id
|
||||
== data['data']['records'][2]['workout_id']
|
||||
)
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert 'value' in data['data']['records'][2]
|
||||
|
||||
assert (
|
||||
'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert (
|
||||
activity_cycling_user_1.short_id
|
||||
== data['data']['records'][3]['activity_id']
|
||||
workout_cycling_user_1.short_id
|
||||
== data['data']['records'][3]['workout_id']
|
||||
)
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 'value' in data['data']['records'][3]
|
||||
|
||||
def test_it_gets_no_records_if_user_has_no_activity(
|
||||
def test_it_gets_no_records_if_user_has_no_workout(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -115,7 +115,7 @@ class TestGetRecords:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['records']) == 0
|
||||
|
||||
def test_it_gets_no_records_if_activity_has_zero_value(
|
||||
def test_it_gets_no_records_if_workout_has_zero_value(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -129,15 +129,15 @@ class TestGetRecords:
|
||||
content_type='application/json',
|
||||
)
|
||||
client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=0,
|
||||
activity_date='2018-05-14 14:05',
|
||||
workout_date='2018-05-14 14:05',
|
||||
distance=0,
|
||||
title='Activity test',
|
||||
title='Workout test',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -158,7 +158,7 @@ class TestGetRecords:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['records']) == 0
|
||||
|
||||
def test_it_gets_updated_records_after_activities_post_and_patch(
|
||||
def test_it_gets_updated_records_after_workouts_post_and_patch(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -168,15 +168,15 @@ class TestGetRecords:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-14 14:05',
|
||||
workout_date='2018-05-14 14:05',
|
||||
distance=7,
|
||||
title='Activity test 1',
|
||||
title='Workout test 1',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -185,7 +185,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_short_id = data['data']['activities'][0]['id']
|
||||
workout_1_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -201,56 +201,56 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# Post activity with lower duration (same sport)
|
||||
# Post workout with lower duration (same sport)
|
||||
# => 2 new records: Average speed and Max speed
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3000,
|
||||
activity_date='2018-05-15 14:05',
|
||||
workout_date='2018-05-15 14:05',
|
||||
distance=7,
|
||||
title='Activity test 2',
|
||||
title='Workout test 2',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -259,7 +259,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_short_id = data['data']['activities'][0]['id']
|
||||
workout_2_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -275,55 +275,55 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# Post activity with no new records
|
||||
# Post workout with no new records
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3500,
|
||||
activity_date='2018-05-16 14:05',
|
||||
workout_date='2018-05-16 14:05',
|
||||
distance=6.5,
|
||||
title='Activity test 3',
|
||||
title='Workout test 3',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -332,7 +332,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_3_short_id = data['data']['activities'][0]['id']
|
||||
workout_3_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -348,48 +348,48 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# Edit last activity
|
||||
# Edit last workout
|
||||
# 1 new record: Longest duration
|
||||
client.patch(
|
||||
f'/api/activities/{activity_3_short_id}',
|
||||
f'/api/workouts/{workout_3_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(duration=4000)),
|
||||
headers=dict(
|
||||
@ -412,47 +412,47 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 8.4 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_3_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Tue, 15 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 8.4 == data['data']['records'][3]['value']
|
||||
|
||||
# delete activity 2 => AS and MS record update
|
||||
# delete workout 2 => AS and MS record update
|
||||
client.delete(
|
||||
f'/api/activities/{activity_2_short_id}',
|
||||
f'/api/workouts/{workout_2_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -473,56 +473,56 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_3_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# add an activity with the same data as activity 1 except with a
|
||||
# add a workout with the same data as workout 1 except with a
|
||||
# later date => no change in record
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-20 14:05',
|
||||
workout_date='2018-05-20 14:05',
|
||||
distance=7,
|
||||
title='Activity test 4',
|
||||
title='Workout test 4',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -531,7 +531,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_short_id = data['data']['activities'][0]['id']
|
||||
workout_4_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -547,58 +547,58 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_3_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# add an activity with the same data as activity 1 except with
|
||||
# add a workout with the same data as workout 1 except with
|
||||
# an earlier date
|
||||
# => record update (activity 5 replace activity 1)
|
||||
# => record update (workout 5 replace workout 1)
|
||||
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-14 08:05',
|
||||
workout_date='2018-05-14 08:05',
|
||||
distance=7,
|
||||
title='Activity test 5',
|
||||
title='Workout test 5',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -607,7 +607,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_5_short_id = data['data']['activities'][0]['id']
|
||||
workout_5_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -623,68 +623,68 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 08:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_5_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_5_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 08:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_5_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_5_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_3_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_3_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:06:40' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 08:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_5_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_5_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
# delete all activities - no more records
|
||||
# delete all workouts - no more records
|
||||
client.delete(
|
||||
f'/api/activities/{activity_1_short_id}',
|
||||
f'/api/workouts/{workout_1_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_3_short_id}',
|
||||
f'/api/workouts/{workout_3_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_4_short_id}',
|
||||
f'/api/workouts/{workout_4_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
),
|
||||
)
|
||||
client.delete(
|
||||
f'/api/activities/{activity_5_short_id}',
|
||||
f'/api/workouts/{workout_5_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -717,15 +717,15 @@ class TestGetRecords:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-14 14:05',
|
||||
workout_date='2018-05-14 14:05',
|
||||
distance=7,
|
||||
title='Activity test 1',
|
||||
title='Workout test 1',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -734,17 +734,17 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_1_short_id = data['data']['activities'][0]['id']
|
||||
workout_1_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=2,
|
||||
duration=3600,
|
||||
activity_date='2018-05-16 16:05',
|
||||
workout_date='2018-05-16 16:05',
|
||||
distance=20,
|
||||
title='Activity test 2',
|
||||
title='Workout test 2',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -753,17 +753,17 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_2_short_id = data['data']['activities'][0]['id']
|
||||
workout_2_short_id = data['data']['workouts'][0]['id']
|
||||
client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3000,
|
||||
activity_date='2018-05-17 17:05',
|
||||
workout_date='2018-05-17 17:05',
|
||||
distance=3,
|
||||
title='Activity test 3',
|
||||
title='Workout test 3',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -772,15 +772,15 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
response = client.post(
|
||||
'/api/activities/no_gpx',
|
||||
'/api/workouts/no_gpx',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=2,
|
||||
duration=3000,
|
||||
activity_date='2018-05-18 18:05',
|
||||
workout_date='2018-05-18 18:05',
|
||||
distance=10,
|
||||
title='Activity test 4',
|
||||
title='Workout test 4',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -789,7 +789,7 @@ class TestGetRecords:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
activity_4_short_id = data['data']['activities'][0]['id']
|
||||
workout_4_short_id = data['data']['workouts'][0]['id']
|
||||
response = client.get(
|
||||
'/api/records',
|
||||
headers=dict(
|
||||
@ -805,86 +805,86 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 7.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 7.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 7.0 == data['data']['records'][3]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][4]['activity_date']
|
||||
== data['data']['records'][4]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][4]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][4]['workout_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 20.0 == data['data']['records'][4]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][5]['activity_date']
|
||||
== data['data']['records'][5]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][5]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][5]['workout_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 20.0 == data['data']['records'][5]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][6]['activity_date']
|
||||
== data['data']['records'][6]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][6]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][6]['workout_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][6]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][7]['activity_date']
|
||||
== data['data']['records'][7]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][7]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][7]['workout_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 20.0 == data['data']['records'][7]['value']
|
||||
|
||||
client.patch(
|
||||
f'/api/activities/{activity_2_short_id}',
|
||||
f'/api/workouts/{workout_2_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=1)),
|
||||
headers=dict(
|
||||
@ -907,80 +907,80 @@ class TestGetRecords:
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][0]['activity_date']
|
||||
== data['data']['records'][0]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][0]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][0]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][0]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][0]['workout_id']
|
||||
assert 'AS' == data['data']['records'][0]['record_type']
|
||||
assert 20.0 == data['data']['records'][0]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][1]['activity_date']
|
||||
== data['data']['records'][1]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][1]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][1]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][1]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][1]['workout_id']
|
||||
assert 'FD' == data['data']['records'][1]['record_type']
|
||||
assert 20.0 == data['data']['records'][1]['value']
|
||||
|
||||
assert (
|
||||
'Mon, 14 May 2018 14:05:00 GMT'
|
||||
== data['data']['records'][2]['activity_date']
|
||||
== data['data']['records'][2]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][2]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][2]['sport_id']
|
||||
assert activity_1_short_id == data['data']['records'][2]['activity_id']
|
||||
assert workout_1_short_id == data['data']['records'][2]['workout_id']
|
||||
assert 'LD' == data['data']['records'][2]['record_type']
|
||||
assert '1:00:00' == data['data']['records'][2]['value']
|
||||
|
||||
assert (
|
||||
'Wed, 16 May 2018 16:05:00 GMT'
|
||||
== data['data']['records'][3]['activity_date']
|
||||
== data['data']['records'][3]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][3]['user']
|
||||
assert sport_1_cycling.id == data['data']['records'][3]['sport_id']
|
||||
assert activity_2_short_id == data['data']['records'][3]['activity_id']
|
||||
assert workout_2_short_id == data['data']['records'][3]['workout_id']
|
||||
assert 'MS' == data['data']['records'][3]['record_type']
|
||||
assert 20.0 == data['data']['records'][3]['value']
|
||||
|
||||
assert (
|
||||
'Fri, 18 May 2018 18:05:00 GMT'
|
||||
== data['data']['records'][4]['activity_date']
|
||||
== data['data']['records'][4]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][4]['user']
|
||||
assert sport_2_running.id == data['data']['records'][4]['sport_id']
|
||||
assert activity_4_short_id == data['data']['records'][4]['activity_id']
|
||||
assert workout_4_short_id == data['data']['records'][4]['workout_id']
|
||||
assert 'AS' == data['data']['records'][4]['record_type']
|
||||
assert 12.0 == data['data']['records'][4]['value']
|
||||
|
||||
assert (
|
||||
'Fri, 18 May 2018 18:05:00 GMT'
|
||||
== data['data']['records'][5]['activity_date']
|
||||
== data['data']['records'][5]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][5]['user']
|
||||
assert sport_2_running.id == data['data']['records'][5]['sport_id']
|
||||
assert activity_4_short_id == data['data']['records'][5]['activity_id']
|
||||
assert workout_4_short_id == data['data']['records'][5]['workout_id']
|
||||
assert 'FD' == data['data']['records'][5]['record_type']
|
||||
assert 10.0 == data['data']['records'][5]['value']
|
||||
|
||||
assert (
|
||||
'Fri, 18 May 2018 18:05:00 GMT'
|
||||
== data['data']['records'][6]['activity_date']
|
||||
== data['data']['records'][6]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][6]['user']
|
||||
assert sport_2_running.id == data['data']['records'][6]['sport_id']
|
||||
assert activity_4_short_id == data['data']['records'][6]['activity_id']
|
||||
assert workout_4_short_id == data['data']['records'][6]['workout_id']
|
||||
assert 'LD' == data['data']['records'][6]['record_type']
|
||||
assert '0:50:00' == data['data']['records'][6]['value']
|
||||
|
||||
assert (
|
||||
'Fri, 18 May 2018 18:05:00 GMT'
|
||||
== data['data']['records'][7]['activity_date']
|
||||
== data['data']['records'][7]['workout_date']
|
||||
) # noqa
|
||||
assert 'test' == data['data']['records'][7]['user']
|
||||
assert sport_2_running.id == data['data']['records'][7]['sport_id']
|
||||
assert activity_4_short_id == data['data']['records'][7]['activity_id']
|
||||
assert workout_4_short_id == data['data']['records'][7]['workout_id']
|
||||
assert 'MS' == data['data']['records'][7]['record_type']
|
||||
assert 12.0 == data['data']['records'][7]['value']
|
@ -1,7 +1,7 @@
|
||||
import datetime
|
||||
|
||||
from fittrackee.activities.models import Activity, Record, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Record, Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
@ -11,27 +11,27 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_ld = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='LD',
|
||||
).first()
|
||||
assert 'test' == record_ld.user.username
|
||||
assert 1 == record_ld.sport_id
|
||||
assert 1 == record_ld.activity_id
|
||||
assert 1 == record_ld.workout_id
|
||||
assert 'LD' == record_ld.record_type
|
||||
assert '2018-01-01 00:00:00' == str(record_ld.activity_date)
|
||||
assert '2018-01-01 00:00:00' == str(record_ld.workout_date)
|
||||
assert '<Record Cycling - LD - 2018-01-01>' == str(record_ld)
|
||||
|
||||
record_serialize = record_ld.serialize()
|
||||
assert 'id' in record_serialize
|
||||
assert 'user' in record_serialize
|
||||
assert 'sport_id' in record_serialize
|
||||
assert 'activity_id' in record_serialize
|
||||
assert 'workout_id' in record_serialize
|
||||
assert 'record_type' in record_serialize
|
||||
assert 'activity_date' in record_serialize
|
||||
assert 'workout_date' in record_serialize
|
||||
assert 'value' in record_serialize
|
||||
|
||||
def test_record_model_with_none_value(
|
||||
@ -39,19 +39,19 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_ld = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='LD',
|
||||
).first()
|
||||
record_ld.value = None
|
||||
assert 'test' == record_ld.user.username
|
||||
assert 1 == record_ld.sport_id
|
||||
assert 1 == record_ld.activity_id
|
||||
assert 1 == record_ld.workout_id
|
||||
assert 'LD' == record_ld.record_type
|
||||
assert '2018-01-01 00:00:00' == str(record_ld.activity_date)
|
||||
assert '2018-01-01 00:00:00' == str(record_ld.workout_date)
|
||||
assert '<Record Cycling - LD - 2018-01-01>' == str(record_ld)
|
||||
assert record_ld.value is None
|
||||
|
||||
@ -63,11 +63,11 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_as = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='AS',
|
||||
).first()
|
||||
|
||||
@ -84,11 +84,11 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_fd = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='FD',
|
||||
).first()
|
||||
|
||||
@ -105,11 +105,11 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_ld = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='LD',
|
||||
).first()
|
||||
|
||||
@ -126,11 +126,11 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_ld = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='LD',
|
||||
).first()
|
||||
record_ld.value = datetime.timedelta(seconds=0)
|
||||
@ -148,11 +148,11 @@ class TestRecordModel:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
record_ms = Record.query.filter_by(
|
||||
user_id=activity_cycling_user_1.user_id,
|
||||
sport_id=activity_cycling_user_1.sport_id,
|
||||
user_id=workout_cycling_user_1.user_id,
|
||||
sport_id=workout_cycling_user_1.sport_id,
|
||||
record_type='MS',
|
||||
).first()
|
||||
|
@ -1,7 +1,7 @@
|
||||
import json
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
expected_sport_1_cycling_result = {
|
||||
@ -11,7 +11,7 @@ expected_sport_1_cycling_result = {
|
||||
'is_active': True,
|
||||
}
|
||||
expected_sport_1_cycling_admin_result = expected_sport_1_cycling_result.copy()
|
||||
expected_sport_1_cycling_admin_result['has_activities'] = False
|
||||
expected_sport_1_cycling_admin_result['has_workouts'] = False
|
||||
|
||||
expected_sport_2_running_result = {
|
||||
'id': 2,
|
||||
@ -20,7 +20,7 @@ expected_sport_2_running_result = {
|
||||
'is_active': True,
|
||||
}
|
||||
expected_sport_2_running_admin_result = expected_sport_2_running_result.copy()
|
||||
expected_sport_2_running_admin_result['has_activities'] = False
|
||||
expected_sport_2_running_admin_result['has_workouts'] = False
|
||||
|
||||
expected_sport_1_cycling_inactive_result = {
|
||||
'id': 1,
|
||||
@ -31,7 +31,7 @@ expected_sport_1_cycling_inactive_result = {
|
||||
expected_sport_1_cycling_inactive_admin_result = (
|
||||
expected_sport_1_cycling_inactive_result.copy()
|
||||
)
|
||||
expected_sport_1_cycling_inactive_admin_result['has_activities'] = False
|
||||
expected_sport_1_cycling_inactive_admin_result['has_workouts'] = False
|
||||
|
||||
|
||||
class TestGetSports:
|
||||
@ -266,7 +266,7 @@ class TestUpdateSport:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['sports']) == 1
|
||||
assert data['data']['sports'][0]['is_active'] is False
|
||||
assert data['data']['sports'][0]['has_activities'] is False
|
||||
assert data['data']['sports'][0]['has_workouts'] is False
|
||||
|
||||
def test_it_enables_a_sport(
|
||||
self, app: Flask, user_1_admin: User, sport_1_cycling: Sport
|
||||
@ -296,14 +296,14 @@ class TestUpdateSport:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['sports']) == 1
|
||||
assert data['data']['sports'][0]['is_active'] is True
|
||||
assert data['data']['sports'][0]['has_activities'] is False
|
||||
assert data['data']['sports'][0]['has_workouts'] is False
|
||||
|
||||
def test_it_disables_a_sport_with_activities(
|
||||
def test_it_disables_a_sport_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -329,14 +329,14 @@ class TestUpdateSport:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['sports']) == 1
|
||||
assert data['data']['sports'][0]['is_active'] is False
|
||||
assert data['data']['sports'][0]['has_activities'] is True
|
||||
assert data['data']['sports'][0]['has_workouts'] is True
|
||||
|
||||
def test_it_enables_a_sport_with_activities(
|
||||
def test_it_enables_a_sport_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
sport_1_cycling.is_active = False
|
||||
client = app.test_client()
|
||||
@ -363,7 +363,7 @@ class TestUpdateSport:
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['sports']) == 1
|
||||
assert data['data']['sports'][0]['is_active'] is True
|
||||
assert data['data']['sports'][0]['has_activities'] is True
|
||||
assert data['data']['sports'][0]['has_workouts'] is True
|
||||
|
||||
def test_returns_error_if_user_has_no_admin_rights(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
@ -1,7 +1,7 @@
|
||||
from typing import Dict, Optional
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
@ -22,24 +22,24 @@ class TestSportModel:
|
||||
|
||||
def test_sport_model(self, app: Flask, sport_1_cycling: Sport) -> None:
|
||||
serialized_sport = self.assert_sport_model(sport_1_cycling)
|
||||
assert 'has_activities' not in serialized_sport
|
||||
assert 'has_workouts' not in serialized_sport
|
||||
|
||||
def test_sport_model_with_activity(
|
||||
def test_sport_model_with_workout(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
serialized_sport = self.assert_sport_model(sport_1_cycling)
|
||||
assert 'has_activities' not in serialized_sport
|
||||
assert 'has_workouts' not in serialized_sport
|
||||
|
||||
def test_sport_model_with_activity_as_admin(
|
||||
def test_sport_model_with_workout_as_admin(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
serialized_sport = self.assert_sport_model(sport_1_cycling, True)
|
||||
assert serialized_sport['has_activities'] is True
|
||||
assert serialized_sport['has_workouts'] is True
|
@ -1,12 +1,12 @@
|
||||
import json
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestGetStatsByTime:
|
||||
def test_it_gets_no_stats_when_user_has_no_activities(
|
||||
def test_it_gets_no_stats_when_user_has_no_workouts(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -58,8 +58,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -90,8 +90,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -113,14 +113,14 @@ class TestGetStatsByTime:
|
||||
assert 'fail' in data['status']
|
||||
assert 'Invalid time period.' in data['message']
|
||||
|
||||
def test_it_gets_stats_by_time_all_activities(
|
||||
def test_it_gets_stats_by_time_all_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -143,19 +143,19 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 15.0,
|
||||
'total_duration': 4480,
|
||||
}
|
||||
},
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 5,
|
||||
'nb_workouts': 5,
|
||||
'total_distance': 39.0,
|
||||
'total_duration': 11624,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -168,8 +168,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -192,12 +192,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -210,8 +210,8 @@ class TestGetStatsByTime:
|
||||
user_1_paris: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -235,12 +235,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -253,8 +253,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -277,19 +277,19 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 15.0,
|
||||
'total_duration': 4480,
|
||||
}
|
||||
},
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 5,
|
||||
'nb_workouts': 5,
|
||||
'total_distance': 39.0,
|
||||
'total_duration': 11624,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -302,8 +302,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -326,12 +326,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -344,8 +344,8 @@ class TestGetStatsByTime:
|
||||
user_1_paris: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -368,12 +368,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -386,8 +386,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -410,47 +410,47 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017-03': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 5.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2017-06': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3456,
|
||||
}
|
||||
},
|
||||
'2018-01': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2018-02': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 11.0,
|
||||
'total_duration': 1600,
|
||||
}
|
||||
},
|
||||
'2018-04': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
},
|
||||
'2018-05': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3000,
|
||||
}
|
||||
@ -463,8 +463,8 @@ class TestGetStatsByTime:
|
||||
user_1_full: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -487,47 +487,47 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017-03': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 5.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2017-06': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3456,
|
||||
}
|
||||
},
|
||||
'2018-01': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2018-02': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 11.0,
|
||||
'total_duration': 1600,
|
||||
}
|
||||
},
|
||||
'2018-04': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
},
|
||||
'2018-05': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3000,
|
||||
}
|
||||
@ -540,8 +540,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -564,12 +564,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018-04': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -582,8 +582,8 @@ class TestGetStatsByTime:
|
||||
user_1_full: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -606,47 +606,47 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017-03-19': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 5.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2017-05-28': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3456,
|
||||
}
|
||||
},
|
||||
'2017-12-31': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2018-02-18': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 11.0,
|
||||
'total_duration': 1600,
|
||||
}
|
||||
},
|
||||
'2018-04-01': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
},
|
||||
'2018-05-06': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3000,
|
||||
}
|
||||
@ -659,8 +659,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -683,12 +683,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018-04-01': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -701,8 +701,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -725,47 +725,47 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2017-03-20': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 5.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2017-05-29': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3456,
|
||||
}
|
||||
},
|
||||
'2018-01-01': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 1024,
|
||||
}
|
||||
},
|
||||
'2018-02-19': {
|
||||
'1': {
|
||||
'nb_activities': 2,
|
||||
'nb_workouts': 2,
|
||||
'total_distance': 11.0,
|
||||
'total_duration': 1600,
|
||||
}
|
||||
},
|
||||
'2018-03-26': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
},
|
||||
'2018-05-07': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 10.0,
|
||||
'total_duration': 3000,
|
||||
}
|
||||
@ -778,8 +778,8 @@ class TestGetStatsByTime:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -802,12 +802,12 @@ class TestGetStatsByTime:
|
||||
assert data['data']['statistics'] == {
|
||||
'2018-03-26': {
|
||||
'1': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 8.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -822,8 +822,8 @@ class TestGetStatsBySport:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -845,12 +845,12 @@ class TestGetStatsBySport:
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['statistics'] == {
|
||||
'1': {
|
||||
'nb_activities': 7,
|
||||
'nb_workouts': 7,
|
||||
'total_distance': 54.0,
|
||||
'total_duration': 16104,
|
||||
},
|
||||
'2': {
|
||||
'nb_activities': 1,
|
||||
'nb_workouts': 1,
|
||||
'total_distance': 12.0,
|
||||
'total_duration': 6000,
|
||||
},
|
||||
@ -862,8 +862,8 @@ class TestGetStatsBySport:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -885,7 +885,7 @@ class TestGetStatsBySport:
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['statistics'] == {
|
||||
'1': {
|
||||
'nb_activities': 7,
|
||||
'nb_workouts': 7,
|
||||
'total_distance': 54.0,
|
||||
'total_duration': 16104,
|
||||
}
|
||||
@ -897,8 +897,8 @@ class TestGetStatsBySport:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -926,8 +926,8 @@ class TestGetStatsBySport:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -955,8 +955,8 @@ class TestGetStatsBySport:
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
seven_activities_user_1: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
seven_workouts_user_1: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -983,7 +983,7 @@ class TestGetStatsBySport:
|
||||
|
||||
|
||||
class TestGetAllStats:
|
||||
def test_it_returns_all_stats_when_users_have_no_activities(
|
||||
def test_it_returns_all_stats_when_users_have_no_workouts(
|
||||
self, app: Flask, user_1_admin: User, user_2: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -1006,12 +1006,12 @@ class TestGetAllStats:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['activities'] == 0
|
||||
assert data['data']['workouts'] == 0
|
||||
assert data['data']['sports'] == 0
|
||||
assert data['data']['users'] == 2
|
||||
assert 'uploads_dir_size' in data['data']
|
||||
|
||||
def test_it_gets_app_all_stats_with_activities(
|
||||
def test_it_gets_app_all_stats_with_workouts(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_admin: User,
|
||||
@ -1019,9 +1019,9 @@ class TestGetAllStats:
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_cycling_user_2: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_cycling_user_2: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -1043,7 +1043,7 @@ class TestGetAllStats:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert data['data']['activities'] == 3
|
||||
assert data['data']['workouts'] == 3
|
||||
assert data['data']['sports'] == 2
|
||||
assert data['data']['users'] == 3
|
||||
assert 'uploads_dir_size' in data['data']
|
||||
@ -1056,9 +1056,9 @@ class TestGetAllStats:
|
||||
user_3: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
activity_cycling_user_2: Activity,
|
||||
activity_running_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_cycling_user_2: Workout,
|
||||
workout_running_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,59 +1,59 @@
|
||||
import json
|
||||
from typing import Dict
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.activities.utils_id import decode_short_id
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
from flask import Flask
|
||||
|
||||
from .utils import get_random_short_id, post_an_activity
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
||||
def assert_activity_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
def assert_workout_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
assert 'creation_date' in data['data']['workouts'][0]
|
||||
assert (
|
||||
'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
== data['data']['activities'][0]['activity_date']
|
||||
== data['data']['workouts'][0]['workout_date']
|
||||
)
|
||||
assert 'test' == data['data']['activities'][0]['user']
|
||||
assert '0:04:10' == data['data']['activities'][0]['duration']
|
||||
assert data['data']['activities'][0]['ascent'] == 0.4
|
||||
assert data['data']['activities'][0]['ave_speed'] == 4.61
|
||||
assert data['data']['activities'][0]['descent'] == 23.4
|
||||
assert data['data']['activities'][0]['distance'] == 0.32
|
||||
assert data['data']['activities'][0]['max_alt'] == 998.0
|
||||
assert data['data']['activities'][0]['max_speed'] == 5.12
|
||||
assert data['data']['activities'][0]['min_alt'] == 975.0
|
||||
assert data['data']['activities'][0]['moving'] == '0:04:10'
|
||||
assert data['data']['activities'][0]['pauses'] is None
|
||||
assert data['data']['activities'][0]['with_gpx'] is True
|
||||
assert 'test' == data['data']['workouts'][0]['user']
|
||||
assert '0:04:10' == data['data']['workouts'][0]['duration']
|
||||
assert data['data']['workouts'][0]['ascent'] == 0.4
|
||||
assert data['data']['workouts'][0]['ave_speed'] == 4.61
|
||||
assert data['data']['workouts'][0]['descent'] == 23.4
|
||||
assert data['data']['workouts'][0]['distance'] == 0.32
|
||||
assert data['data']['workouts'][0]['max_alt'] == 998.0
|
||||
assert data['data']['workouts'][0]['max_speed'] == 5.12
|
||||
assert data['data']['workouts'][0]['min_alt'] == 975.0
|
||||
assert data['data']['workouts'][0]['moving'] == '0:04:10'
|
||||
assert data['data']['workouts'][0]['pauses'] is None
|
||||
assert data['data']['workouts'][0]['with_gpx'] is True
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_id
|
||||
assert records[0]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['value'] == 5.12
|
||||
assert records[1]['sport_id'] == sport_id
|
||||
assert records[1]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[1]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['value'] == '0:04:10'
|
||||
assert records[2]['sport_id'] == sport_id
|
||||
assert records[2]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[2]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 0.32
|
||||
assert records[3]['sport_id'] == sport_id
|
||||
assert records[3]['activity_id'] == data['data']['activities'][0]['id']
|
||||
assert records[3]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.61
|
||||
|
||||
|
||||
class TestEditActivityWithGpx:
|
||||
def test_it_updates_title_for_an_activity_with_gpx(
|
||||
class TestEditWorkoutWithGpx:
|
||||
def test_it_updates_title_for_an_workout_with_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -61,25 +61,25 @@ class TestEditActivityWithGpx:
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
data=json.dumps(dict(sport_id=2, title="Workout test")),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert sport_2_running.id == data['data']['activities'][0]['sport_id']
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert_activity_data_with_gpx(data, sport_2_running.id)
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert sport_2_running.id == data['data']['workouts'][0]['sport_id']
|
||||
assert data['data']['workouts'][0]['title'] == 'Workout test'
|
||||
assert_workout_data_with_gpx(data, sport_2_running.id)
|
||||
|
||||
def test_it_adds_notes_for_an_activity_with_gpx(
|
||||
def test_it_adds_notes_for_an_workout_with_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -87,11 +87,11 @@ class TestEditActivityWithGpx:
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes="test notes")),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -100,11 +100,11 @@ class TestEditActivityWithGpx:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert data['data']['activities'][0]['title'] == 'just an activity'
|
||||
assert data['data']['activities'][0]['notes'] == 'test notes'
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert data['data']['workouts'][0]['title'] == 'just a workout'
|
||||
assert data['data']['workouts'][0]['notes'] == 'test notes'
|
||||
|
||||
def test_it_raises_403_when_editing_an_activity_from_different_user(
|
||||
def test_it_raises_403_when_editing_an_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -113,7 +113,7 @@ class TestEditActivityWithGpx:
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, activity_short_id = post_an_activity(app, gpx_file)
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -122,9 +122,9 @@ class TestEditActivityWithGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, title="Activity test")),
|
||||
data=json.dumps(dict(sport_id=2, title="Workout test")),
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -144,11 +144,11 @@ class TestEditActivityWithGpx:
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -157,19 +157,19 @@ class TestEditActivityWithGpx:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert sport_2_running.id == data['data']['activities'][0]['sport_id']
|
||||
assert data['data']['activities'][0]['title'] == 'just an activity'
|
||||
assert_activity_data_with_gpx(data, sport_2_running.id)
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert sport_2_running.id == data['data']['workouts'][0]['sport_id']
|
||||
assert data['data']['workouts'][0]['title'] == 'just a workout'
|
||||
assert_workout_data_with_gpx(data, sport_2_running.id)
|
||||
|
||||
def test_it_returns_400_if_payload_is_empty(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -183,11 +183,11 @@ class TestEditActivityWithGpx:
|
||||
def test_it_raises_500_if_sport_does_not_exists(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -202,16 +202,16 @@ class TestEditActivityWithGpx:
|
||||
)
|
||||
|
||||
|
||||
class TestEditActivityWithoutGpx:
|
||||
def test_it_updates_an_activity_wo_gpx(
|
||||
class TestEditWorkoutWithoutGpx:
|
||||
def test_it_updates_an_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
workout_short_id = workout_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -220,15 +220,15 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=2,
|
||||
duration=3600,
|
||||
activity_date='2018-05-15 15:05',
|
||||
workout_date='2018-05-15 15:05',
|
||||
distance=8,
|
||||
title='Activity test',
|
||||
title='Workout test',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -241,62 +241,62 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 'creation_date' in data['data']['workouts'][0]
|
||||
assert (
|
||||
data['data']['activities'][0]['activity_date']
|
||||
data['data']['workouts'][0]['workout_date']
|
||||
== 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
assert data['data']['activities'][0]['ave_speed'] == 8.0
|
||||
assert data['data']['activities'][0]['descent'] is None
|
||||
assert data['data']['activities'][0]['distance'] == 8.0
|
||||
assert data['data']['activities'][0]['max_alt'] is None
|
||||
assert data['data']['activities'][0]['max_speed'] == 8.0
|
||||
assert data['data']['activities'][0]['min_alt'] is None
|
||||
assert data['data']['activities'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['pauses'] is None
|
||||
assert data['data']['activities'][0]['with_gpx'] is False
|
||||
assert data['data']['activities'][0]['map'] is None
|
||||
assert data['data']['activities'][0]['weather_start'] is None
|
||||
assert data['data']['activities'][0]['weather_end'] is None
|
||||
assert data['data']['activities'][0]['notes'] is None
|
||||
assert data['data']['workouts'][0]['user'] == 'test'
|
||||
assert data['data']['workouts'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['workouts'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['title'] == 'Workout test'
|
||||
assert data['data']['workouts'][0]['ascent'] is None
|
||||
assert data['data']['workouts'][0]['ave_speed'] == 8.0
|
||||
assert data['data']['workouts'][0]['descent'] is None
|
||||
assert data['data']['workouts'][0]['distance'] == 8.0
|
||||
assert data['data']['workouts'][0]['max_alt'] is None
|
||||
assert data['data']['workouts'][0]['max_speed'] == 8.0
|
||||
assert data['data']['workouts'][0]['min_alt'] is None
|
||||
assert data['data']['workouts'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['pauses'] is None
|
||||
assert data['data']['workouts'][0]['with_gpx'] is False
|
||||
assert data['data']['workouts'][0]['map'] is None
|
||||
assert data['data']['workouts'][0]['weather_start'] is None
|
||||
assert data['data']['workouts'][0]['weather_end'] is None
|
||||
assert data['data']['workouts'][0]['notes'] is None
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
assert records[0]['workout_id'] == workout_short_id
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[0]['workout_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[0]['value'] == 8.0
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
assert records[1]['workout_id'] == workout_short_id
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[1]['workout_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
assert records[2]['workout_id'] == workout_short_id
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[2]['workout_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[2]['value'] == 8.0
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
assert records[3]['workout_id'] == workout_short_id
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[3]['workout_date'] == 'Tue, 15 May 2018 15:05:00 GMT'
|
||||
assert records[3]['value'] == 8.0
|
||||
|
||||
def test_it_adds_notes_to_an_activity_wo_gpx(
|
||||
def test_it_adds_notes_to_an_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
workout_short_id = workout_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -305,7 +305,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(notes='test notes')),
|
||||
headers=dict(
|
||||
@ -317,61 +317,61 @@ class TestEditActivityWithoutGpx:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 'creation_date' in data['data']['workouts'][0]
|
||||
assert (
|
||||
data['data']['activities'][0]['activity_date']
|
||||
data['data']['workouts'][0]['workout_date']
|
||||
== 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_1_cycling.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] is None
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
assert data['data']['activities'][0]['ave_speed'] == 10.0
|
||||
assert data['data']['activities'][0]['descent'] is None
|
||||
assert data['data']['activities'][0]['distance'] == 10.0
|
||||
assert data['data']['activities'][0]['max_alt'] is None
|
||||
assert data['data']['activities'][0]['max_speed'] == 10.0
|
||||
assert data['data']['activities'][0]['min_alt'] is None
|
||||
assert data['data']['activities'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['pauses'] is None
|
||||
assert data['data']['activities'][0]['with_gpx'] is False
|
||||
assert data['data']['activities'][0]['map'] is None
|
||||
assert data['data']['activities'][0]['weather_start'] is None
|
||||
assert data['data']['activities'][0]['weather_end'] is None
|
||||
assert data['data']['activities'][0]['notes'] == 'test notes'
|
||||
assert data['data']['workouts'][0]['user'] == 'test'
|
||||
assert data['data']['workouts'][0]['sport_id'] == sport_1_cycling.id
|
||||
assert data['data']['workouts'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['title'] is None
|
||||
assert data['data']['workouts'][0]['ascent'] is None
|
||||
assert data['data']['workouts'][0]['ave_speed'] == 10.0
|
||||
assert data['data']['workouts'][0]['descent'] is None
|
||||
assert data['data']['workouts'][0]['distance'] == 10.0
|
||||
assert data['data']['workouts'][0]['max_alt'] is None
|
||||
assert data['data']['workouts'][0]['max_speed'] == 10.0
|
||||
assert data['data']['workouts'][0]['min_alt'] is None
|
||||
assert data['data']['workouts'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['pauses'] is None
|
||||
assert data['data']['workouts'][0]['with_gpx'] is False
|
||||
assert data['data']['workouts'][0]['map'] is None
|
||||
assert data['data']['workouts'][0]['weather_start'] is None
|
||||
assert data['data']['workouts'][0]['weather_end'] is None
|
||||
assert data['data']['workouts'][0]['notes'] == 'test notes'
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_1_cycling.id
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
assert records[0]['workout_id'] == workout_short_id
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['value'] == 10.0
|
||||
assert records[1]['sport_id'] == sport_1_cycling.id
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
assert records[1]['workout_id'] == workout_short_id
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == sport_1_cycling.id
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
assert records[2]['workout_id'] == workout_short_id
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['value'] == 10.0
|
||||
assert records[3]['sport_id'] == sport_1_cycling.id
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
assert records[3]['workout_id'] == workout_short_id
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['value'] == 10.0
|
||||
|
||||
def test_returns_403_when_editing_an_activity_wo_gpx_from_different_user(
|
||||
def test_returns_403_when_editing_an_workout_wo_gpx_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_2: Activity,
|
||||
workout_cycling_user_2: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -381,15 +381,15 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_2.short_id}',
|
||||
f'/api/workouts/{workout_cycling_user_2.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=2,
|
||||
duration=3600,
|
||||
activity_date='2018-05-15 15:05',
|
||||
workout_date='2018-05-15 15:05',
|
||||
distance=8,
|
||||
title='Activity test',
|
||||
title='Workout test',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -403,15 +403,15 @@ class TestEditActivityWithoutGpx:
|
||||
assert 'error' in data['status']
|
||||
assert 'You do not have permissions.' in data['message']
|
||||
|
||||
def test_it_updates_an_activity_wo_gpx_with_timezone(
|
||||
def test_it_updates_an_workout_wo_gpx_with_timezone(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_paris: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
workout_short_id = workout_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -420,15 +420,15 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=2,
|
||||
duration=3600,
|
||||
activity_date='2018-05-15 15:05',
|
||||
workout_date='2018-05-15 15:05',
|
||||
distance=8,
|
||||
title='Activity test',
|
||||
title='Workout test',
|
||||
)
|
||||
),
|
||||
headers=dict(
|
||||
@ -440,59 +440,59 @@ class TestEditActivityWithoutGpx:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 'creation_date' in data['data']['workouts'][0]
|
||||
assert (
|
||||
data['data']['activities'][0]['activity_date']
|
||||
data['data']['workouts'][0]['workout_date']
|
||||
== 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] == 'Activity test'
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
assert data['data']['activities'][0]['ave_speed'] == 8.0
|
||||
assert data['data']['activities'][0]['descent'] is None
|
||||
assert data['data']['activities'][0]['distance'] == 8.0
|
||||
assert data['data']['activities'][0]['max_alt'] is None
|
||||
assert data['data']['activities'][0]['max_speed'] == 8.0
|
||||
assert data['data']['activities'][0]['min_alt'] is None
|
||||
assert data['data']['activities'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['pauses'] is None
|
||||
assert data['data']['activities'][0]['with_gpx'] is False
|
||||
assert data['data']['workouts'][0]['user'] == 'test'
|
||||
assert data['data']['workouts'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['workouts'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['title'] == 'Workout test'
|
||||
assert data['data']['workouts'][0]['ascent'] is None
|
||||
assert data['data']['workouts'][0]['ave_speed'] == 8.0
|
||||
assert data['data']['workouts'][0]['descent'] is None
|
||||
assert data['data']['workouts'][0]['distance'] == 8.0
|
||||
assert data['data']['workouts'][0]['max_alt'] is None
|
||||
assert data['data']['workouts'][0]['max_speed'] == 8.0
|
||||
assert data['data']['workouts'][0]['min_alt'] is None
|
||||
assert data['data']['workouts'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['pauses'] is None
|
||||
assert data['data']['workouts'][0]['with_gpx'] is False
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
assert records[0]['workout_id'] == workout_short_id
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[0]['workout_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[0]['value'] == 8.0
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
assert records[1]['workout_id'] == workout_short_id
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[1]['workout_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
assert records[2]['workout_id'] == workout_short_id
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[2]['workout_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[2]['value'] == 8.0
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
assert records[3]['workout_id'] == workout_short_id
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[3]['workout_date'] == 'Tue, 15 May 2018 13:05:00 GMT'
|
||||
assert records[3]['value'] == 8.0
|
||||
|
||||
def test_it_updates_only_sport_and_distance_an_activity_wo_gpx(
|
||||
def test_it_updates_only_sport_and_distance_an_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
sport_2_running: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
activity_short_id = activity_cycling_user_1.short_id
|
||||
workout_short_id = workout_cycling_user_1.short_id
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -501,7 +501,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(sport_id=2, distance=20)),
|
||||
headers=dict(
|
||||
@ -513,48 +513,48 @@ class TestEditActivityWithoutGpx:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 'creation_date' in data['data']['activities'][0]
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 'creation_date' in data['data']['workouts'][0]
|
||||
assert (
|
||||
data['data']['activities'][0]['activity_date']
|
||||
data['data']['workouts'][0]['workout_date']
|
||||
== 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
)
|
||||
assert data['data']['activities'][0]['user'] == 'test'
|
||||
assert data['data']['activities'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['activities'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['title'] is None
|
||||
assert data['data']['activities'][0]['ascent'] is None
|
||||
assert data['data']['activities'][0]['ave_speed'] == 20.0
|
||||
assert data['data']['activities'][0]['descent'] is None
|
||||
assert data['data']['activities'][0]['distance'] == 20.0
|
||||
assert data['data']['activities'][0]['max_alt'] is None
|
||||
assert data['data']['activities'][0]['max_speed'] == 20.0
|
||||
assert data['data']['activities'][0]['min_alt'] is None
|
||||
assert data['data']['activities'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['activities'][0]['pauses'] is None
|
||||
assert data['data']['activities'][0]['with_gpx'] is False
|
||||
assert data['data']['workouts'][0]['user'] == 'test'
|
||||
assert data['data']['workouts'][0]['sport_id'] == sport_2_running.id
|
||||
assert data['data']['workouts'][0]['duration'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['title'] is None
|
||||
assert data['data']['workouts'][0]['ascent'] is None
|
||||
assert data['data']['workouts'][0]['ave_speed'] == 20.0
|
||||
assert data['data']['workouts'][0]['descent'] is None
|
||||
assert data['data']['workouts'][0]['distance'] == 20.0
|
||||
assert data['data']['workouts'][0]['max_alt'] is None
|
||||
assert data['data']['workouts'][0]['max_speed'] == 20.0
|
||||
assert data['data']['workouts'][0]['min_alt'] is None
|
||||
assert data['data']['workouts'][0]['moving'] == '1:00:00'
|
||||
assert data['data']['workouts'][0]['pauses'] is None
|
||||
assert data['data']['workouts'][0]['with_gpx'] is False
|
||||
|
||||
records = data['data']['activities'][0]['records']
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == sport_2_running.id
|
||||
assert records[0]['activity_id'] == activity_short_id
|
||||
assert records[0]['workout_id'] == workout_short_id
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[0]['value'] == 20.0
|
||||
assert records[1]['sport_id'] == sport_2_running.id
|
||||
assert records[1]['activity_id'] == activity_short_id
|
||||
assert records[1]['workout_id'] == workout_short_id
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[1]['value'] == '1:00:00'
|
||||
assert records[2]['sport_id'] == sport_2_running.id
|
||||
assert records[2]['activity_id'] == activity_short_id
|
||||
assert records[2]['workout_id'] == workout_short_id
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[2]['value'] == 20.0
|
||||
assert records[3]['sport_id'] == sport_2_running.id
|
||||
assert records[3]['activity_id'] == activity_short_id
|
||||
assert records[3]['workout_id'] == workout_short_id
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['activity_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['workout_date'] == 'Mon, 01 Jan 2018 00:00:00 GMT'
|
||||
assert records[3]['value'] == 20.0
|
||||
|
||||
def test_it_returns_400_if_payload_is_empty(
|
||||
@ -562,7 +562,7 @@ class TestEditActivityWithoutGpx:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -572,7 +572,7 @@ class TestEditActivityWithoutGpx:
|
||||
)
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
f'/api/workouts/{workout_cycling_user_1.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict()),
|
||||
headers=dict(
|
||||
@ -591,7 +591,7 @@ class TestEditActivityWithoutGpx:
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -600,13 +600,13 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
f'/api/workouts/{workout_cycling_user_1.short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='15/2018',
|
||||
workout_date='15/2018',
|
||||
distance=10,
|
||||
)
|
||||
),
|
||||
@ -625,7 +625,7 @@ class TestEditActivityWithoutGpx:
|
||||
in data['message']
|
||||
)
|
||||
|
||||
def test_it_returns_404_if_edited_activity_does_not_exists(
|
||||
def test_it_returns_404_if_edited_workout_does_not_exists(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -635,13 +635,13 @@ class TestEditActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.patch(
|
||||
f'/api/activities/{get_random_short_id()}',
|
||||
f'/api/workouts/{get_random_short_id()}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(
|
||||
dict(
|
||||
sport_id=1,
|
||||
duration=3600,
|
||||
activity_date='2018-05-15 14:05',
|
||||
workout_date='2018-05-15 14:05',
|
||||
distance=10,
|
||||
)
|
||||
),
|
||||
@ -654,11 +654,11 @@ class TestEditActivityWithoutGpx:
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
assert len(data['data']['activities']) == 0
|
||||
assert len(data['data']['workouts']) == 0
|
||||
|
||||
|
||||
class TestRefreshActivityWithGpx:
|
||||
def test_refresh_an_activity_with_gpx(
|
||||
class TestRefreshWorkoutWithGpx:
|
||||
def test_refresh_an_workout_with_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -666,17 +666,17 @@ class TestRefreshActivityWithGpx:
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
activity_uuid = decode_short_id(activity_short_id)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
workout_uuid = decode_short_id(workout_short_id)
|
||||
client = app.test_client()
|
||||
|
||||
# Edit some activity data
|
||||
activity = Activity.query.filter_by(uuid=activity_uuid).first()
|
||||
activity.ascent = 1000
|
||||
activity.min_alt = -100
|
||||
# Edit some workout data
|
||||
workout = Workout.query.filter_by(uuid=workout_uuid).first()
|
||||
workout.ascent = 1000
|
||||
workout.min_alt = -100
|
||||
|
||||
response = client.patch(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
content_type='application/json',
|
||||
data=json.dumps(dict(refresh=True)),
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
@ -685,7 +685,7 @@ class TestRefreshActivityWithGpx:
|
||||
|
||||
assert response.status_code == 200
|
||||
assert 'success' in data['status']
|
||||
assert len(data['data']['activities']) == 1
|
||||
assert 1 == data['data']['activities'][0]['sport_id']
|
||||
assert 0.4 == data['data']['activities'][0]['ascent']
|
||||
assert 975.0 == data['data']['activities'][0]['min_alt']
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert 1 == data['data']['workouts'][0]['sport_id']
|
||||
assert 0.4 == data['data']['workouts'][0]['ascent']
|
||||
assert 975.0 == data['data']['workouts'][0]['min_alt']
|
@ -1,34 +1,34 @@
|
||||
import json
|
||||
import os
|
||||
|
||||
from fittrackee.activities.models import Activity, Sport
|
||||
from fittrackee.activities.utils import get_absolute_file_path
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils import get_absolute_file_path
|
||||
from flask import Flask
|
||||
|
||||
from .utils import get_random_short_id, post_an_activity
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
|
||||
|
||||
def get_gpx_filepath(activity_id: int) -> str:
|
||||
activity = Activity.query.filter_by(id=activity_id).first()
|
||||
return activity.gpx
|
||||
def get_gpx_filepath(workout_id: int) -> str:
|
||||
workout = Workout.query.filter_by(id=workout_id).first()
|
||||
return workout.gpx
|
||||
|
||||
|
||||
class TestDeleteActivityWithGpx:
|
||||
def test_it_deletes_an_activity_with_gpx(
|
||||
class TestDeleteWorkoutWithGpx:
|
||||
def test_it_deletes_an_workout_with_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
assert response.status_code == 204
|
||||
|
||||
def test_it_returns_403_when_deleting_an_activity_from_different_user(
|
||||
def test_it_returns_403_when_deleting_an_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -36,7 +36,7 @@ class TestDeleteActivityWithGpx:
|
||||
sport_1_cycling: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, activity_short_id = post_an_activity(app, gpx_file)
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -45,7 +45,7 @@ class TestDeleteActivityWithGpx:
|
||||
)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -58,7 +58,7 @@ class TestDeleteActivityWithGpx:
|
||||
assert 'error' in data['status']
|
||||
assert 'You do not have permissions.' in data['message']
|
||||
|
||||
def test_it_returns_404_if_activity_does_not_exist(
|
||||
def test_it_returns_404_if_workout_does_not_exist(
|
||||
self, app: Flask, user_1: User
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
@ -68,7 +68,7 @@ class TestDeleteActivityWithGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{get_random_short_id()}',
|
||||
f'/api/workouts/{get_random_short_id()}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -78,17 +78,17 @@ class TestDeleteActivityWithGpx:
|
||||
assert response.status_code == 404
|
||||
assert 'not found' in data['status']
|
||||
|
||||
def test_it_returns_500_when_deleting_an_activity_with_gpx_invalid_file(
|
||||
def test_it_returns_500_when_deleting_an_workout_with_gpx_invalid_file(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, activity_short_id = post_an_activity(app, gpx_file)
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
gpx_filepath = get_gpx_filepath(1)
|
||||
gpx_filepath = get_absolute_file_path(gpx_filepath)
|
||||
os.remove(gpx_filepath)
|
||||
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_short_id}',
|
||||
f'/api/workouts/{workout_short_id}',
|
||||
headers=dict(Authorization=f'Bearer {token}'),
|
||||
)
|
||||
|
||||
@ -102,13 +102,13 @@ class TestDeleteActivityWithGpx:
|
||||
)
|
||||
|
||||
|
||||
class TestDeleteActivityWithoutGpx:
|
||||
def test_it_deletes_an_activity_wo_gpx(
|
||||
class TestDeleteWorkoutWithoutGpx:
|
||||
def test_it_deletes_an_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -117,7 +117,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
f'/api/workouts/{workout_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
||||
@ -125,13 +125,13 @@ class TestDeleteActivityWithoutGpx:
|
||||
)
|
||||
assert response.status_code == 204
|
||||
|
||||
def test_it_returns_403_when_deleting_an_activity_from_different_user(
|
||||
def test_it_returns_403_when_deleting_an_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
user_2: User,
|
||||
sport_1_cycling: Sport,
|
||||
activity_cycling_user_1: Activity,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
@ -140,7 +140,7 @@ class TestDeleteActivityWithoutGpx:
|
||||
content_type='application/json',
|
||||
)
|
||||
response = client.delete(
|
||||
f'/api/activities/{activity_cycling_user_1.short_id}',
|
||||
f'/api/workouts/{workout_cycling_user_1.short_id}',
|
||||
headers=dict(
|
||||
Authorization='Bearer '
|
||||
+ json.loads(resp_login.data.decode())['auth_token']
|
73
fittrackee/tests/workouts/test_workouts_model.py
Normal file
73
fittrackee/tests/workouts/test_workouts_model.py
Normal file
@ -0,0 +1,73 @@
|
||||
from uuid import UUID
|
||||
|
||||
from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
from fittrackee.workouts.utils_id import decode_short_id
|
||||
from flask import Flask
|
||||
|
||||
|
||||
class TestWorkoutModel:
|
||||
def test_workout_model(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
workout_cycling_user_1: Workout,
|
||||
) -> None:
|
||||
workout_cycling_user_1.title = 'Test'
|
||||
|
||||
assert 1 == workout_cycling_user_1.id
|
||||
assert workout_cycling_user_1.uuid is not None
|
||||
assert 1 == workout_cycling_user_1.user_id
|
||||
assert 1 == workout_cycling_user_1.sport_id
|
||||
assert '2018-01-01 00:00:00' == str(
|
||||
workout_cycling_user_1.workout_date
|
||||
)
|
||||
assert 10.0 == float(workout_cycling_user_1.distance)
|
||||
assert '1:00:00' == str(workout_cycling_user_1.duration)
|
||||
assert 'Test' == workout_cycling_user_1.title
|
||||
assert '<Workout \'Cycling\' - 2018-01-01 00:00:00>' == str(
|
||||
workout_cycling_user_1
|
||||
)
|
||||
|
||||
serialized_workout = workout_cycling_user_1.serialize()
|
||||
assert isinstance(decode_short_id(serialized_workout['id']), UUID)
|
||||
assert 'test' == serialized_workout['user']
|
||||
assert 1 == serialized_workout['sport_id']
|
||||
assert serialized_workout['title'] == 'Test'
|
||||
assert 'creation_date' in serialized_workout
|
||||
assert serialized_workout['modification_date'] is not None
|
||||
assert str(serialized_workout['workout_date']) == '2018-01-01 00:00:00'
|
||||
assert serialized_workout['duration'] == '1:00:00'
|
||||
assert serialized_workout['pauses'] is None
|
||||
assert serialized_workout['moving'] == '1:00:00'
|
||||
assert serialized_workout['distance'] == 10.0
|
||||
assert serialized_workout['max_alt'] is None
|
||||
assert serialized_workout['descent'] is None
|
||||
assert serialized_workout['ascent'] is None
|
||||
assert serialized_workout['max_speed'] == 10.0
|
||||
assert serialized_workout['ave_speed'] == 10.0
|
||||
assert serialized_workout['with_gpx'] is False
|
||||
assert serialized_workout['bounds'] == []
|
||||
assert serialized_workout['previous_workout'] is None
|
||||
assert serialized_workout['next_workout'] is None
|
||||
assert serialized_workout['segments'] == []
|
||||
assert serialized_workout['records'] != []
|
||||
assert serialized_workout['map'] is None
|
||||
assert serialized_workout['weather_start'] is None
|
||||
assert serialized_workout['weather_end'] is None
|
||||
assert serialized_workout['notes'] is None
|
||||
|
||||
def test_workout_segment_model(
|
||||
self,
|
||||
app: Flask,
|
||||
sport_1_cycling: Sport,
|
||||
user_1: User,
|
||||
workout_cycling_user_1: Workout,
|
||||
workout_cycling_user_1_segment: Workout,
|
||||
) -> None:
|
||||
assert (
|
||||
f'<Segment \'{workout_cycling_user_1_segment.segment_id}\' '
|
||||
f'for workout \'{workout_cycling_user_1.short_id}\'>'
|
||||
== str(workout_cycling_user_1_segment)
|
||||
)
|
@ -3,7 +3,7 @@ from io import BytesIO
|
||||
from typing import Tuple
|
||||
from uuid import uuid4
|
||||
|
||||
from fittrackee.activities.utils_id import encode_uuid
|
||||
from fittrackee.workouts.utils_id import encode_uuid
|
||||
from flask import Flask
|
||||
|
||||
|
||||
@ -11,7 +11,7 @@ def get_random_short_id() -> str:
|
||||
return encode_uuid(uuid4())
|
||||
|
||||
|
||||
def post_an_activity(app: Flask, gpx_file: str) -> Tuple[str, str]:
|
||||
def post_an_workout(app: Flask, gpx_file: str) -> Tuple[str, str]:
|
||||
client = app.test_client()
|
||||
resp_login = client.post(
|
||||
'/api/auth/login',
|
||||
@ -20,7 +20,7 @@ def post_an_activity(app: Flask, gpx_file: str) -> Tuple[str, str]:
|
||||
)
|
||||
token = json.loads(resp_login.data.decode())['auth_token']
|
||||
response = client.post(
|
||||
'/api/activities',
|
||||
'/api/workouts',
|
||||
data=dict(
|
||||
file=(BytesIO(str.encode(gpx_file)), 'example.gpx'),
|
||||
data='{"sport_id": 1}',
|
||||
@ -30,4 +30,4 @@ def post_an_activity(app: Flask, gpx_file: str) -> Tuple[str, str]:
|
||||
),
|
||||
)
|
||||
data = json.loads(response.data.decode())
|
||||
return token, data['data']['activities'][0]['id']
|
||||
return token, data['data']['workouts'][0]['id']
|
Reference in New Issue
Block a user