Merge branch 'dev' into oauth2
This commit is contained in:
114
fittrackee/tests/fixtures/fixtures_workouts.py
vendored
114
fittrackee/tests/fixtures/fixtures_workouts.py
vendored
@ -452,6 +452,120 @@ def gpx_file_wo_name() -> str:
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def gpx_file_with_offset() -> str:
|
||||
return (
|
||||
'<?xml version=\'1.0\' encoding=\'UTF-8\'?>'
|
||||
'<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>'
|
||||
' <trkseg>'
|
||||
' <trkpt lat="44.68095" lon="6.07367">'
|
||||
' <ele>998</ele>'
|
||||
' <time>2018-03-13T13:44:45+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68091" lon="6.07367">'
|
||||
' <ele>998</ele>'
|
||||
' <time>2018-03-13T13:44:50+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.6808" lon="6.07364">'
|
||||
' <ele>994</ele>'
|
||||
' <time>2018-03-13T13:45:00+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68075" lon="6.07364">'
|
||||
' <ele>994</ele>'
|
||||
' <time>2018-03-13T13:45:05+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68071" lon="6.07364">'
|
||||
' <ele>994</ele>'
|
||||
' <time>2018-03-13T13:45:10+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68049" lon="6.07361">'
|
||||
' <ele>993</ele>'
|
||||
' <time>2018-03-13T13:45:30+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68019" lon="6.07356">'
|
||||
' <ele>992</ele>'
|
||||
' <time>2018-03-13T13:45:55+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.68014" lon="6.07355">'
|
||||
' <ele>992</ele>'
|
||||
' <time>2018-03-13T13:46:00+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67995" lon="6.07358">'
|
||||
' <ele>987</ele>'
|
||||
' <time>2018-03-13T13:46:15+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67977" lon="6.07364">'
|
||||
' <ele>987</ele>'
|
||||
' <time>2018-03-13T13:46:30+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67972" lon="6.07367">'
|
||||
' <ele>987</ele>'
|
||||
' <time>2018-03-13T13:46:35+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67966" lon="6.07368">'
|
||||
' <ele>987</ele>'
|
||||
' <time>2018-03-13T13:46:40+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67961" lon="6.0737">'
|
||||
' <ele>986</ele>'
|
||||
' <time>2018-03-13T13:46:45+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67938" lon="6.07377">'
|
||||
' <ele>986</ele>'
|
||||
' <time>2018-03-13T13:47:05+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67933" lon="6.07381">'
|
||||
' <ele>986</ele>'
|
||||
' <time>2018-03-13T13:47:10+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67922" lon="6.07385">'
|
||||
' <ele>985</ele>'
|
||||
' <time>2018-03-13T13:47:20+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67911" lon="6.0739">'
|
||||
' <ele>980</ele>'
|
||||
' <time>2018-03-13T13:47:30+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.679" lon="6.07399">'
|
||||
' <ele>980</ele>'
|
||||
' <time>2018-03-13T13:47:40+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67896" lon="6.07402">'
|
||||
' <ele>980</ele>'
|
||||
' <time>2018-03-13T13:47:45+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67884" lon="6.07408">'
|
||||
' <ele>979</ele>'
|
||||
' <time>2018-03-13T13:47:55+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67863" lon="6.07423">'
|
||||
' <ele>981</ele>'
|
||||
' <time>2018-03-13T13:48:15+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67858" lon="6.07425">'
|
||||
' <ele>980</ele>'
|
||||
' <time>2018-03-13T13:48:20+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67842" lon="6.07434">'
|
||||
' <ele>979</ele>'
|
||||
' <time>2018-03-13T13:48:35+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67837" lon="6.07435">'
|
||||
' <ele>979</ele>'
|
||||
' <time>2018-03-13T13:48:40+01:00</time>'
|
||||
' </trkpt>'
|
||||
' <trkpt lat="44.67822" lon="6.07442">'
|
||||
' <ele>975</ele>'
|
||||
' <time>2018-03-13T13:48:55+01:00</time>'
|
||||
' </trkpt>'
|
||||
' </trkseg>'
|
||||
' </trk>'
|
||||
'</gpx>'
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def gpx_file_wo_track() -> str:
|
||||
return (
|
||||
|
@ -2,7 +2,7 @@ from unittest.mock import call, patch
|
||||
|
||||
import pytest
|
||||
from flask import Flask
|
||||
from gpxpy.gpx import MovingData
|
||||
from gpxpy.gpx import IGNORE_TOP_SPEED_PERCENTILES, MovingData
|
||||
from werkzeug.datastructures import FileStorage
|
||||
|
||||
from fittrackee.users.models import User, UserSportPreference
|
||||
@ -55,7 +55,12 @@ class TestStoppedSpeedThreshold:
|
||||
assert gpx_track_segment_mock.call_args_list[0] == call(
|
||||
stopped_speed_threshold=expected_threshold
|
||||
)
|
||||
gpx_track_segment_mock.assert_called_with(expected_threshold)
|
||||
gpx_track_segment_mock.assert_called_with(
|
||||
expected_threshold, # stopped_speed_threshold
|
||||
False, # raw
|
||||
IGNORE_TOP_SPEED_PERCENTILES, # speed_extreemes_percentiles
|
||||
True, # ignore_nonstandard_distances
|
||||
)
|
||||
|
||||
def test_it_calls_get_moving_data_with_threshold_depending_from_user_preference( # noqa
|
||||
self,
|
||||
@ -85,4 +90,9 @@ class TestStoppedSpeedThreshold:
|
||||
assert gpx_track_segment_mock.call_args_list[0] == call(
|
||||
stopped_speed_threshold=expected_threshold
|
||||
)
|
||||
gpx_track_segment_mock.assert_called_with(expected_threshold)
|
||||
gpx_track_segment_mock.assert_called_with(
|
||||
expected_threshold, # stopped_speed_threshold
|
||||
False, # raw
|
||||
IGNORE_TOP_SPEED_PERCENTILES, # speed_extreemes_percentiles
|
||||
True, # ignore_nonstandard_distances
|
||||
)
|
||||
|
@ -1,9 +1,27 @@
|
||||
from datetime import datetime
|
||||
from statistics import mean
|
||||
from typing import List
|
||||
from typing import List, Union
|
||||
|
||||
import pytest
|
||||
import pytz
|
||||
from gpxpy.gpxfield import SimpleTZ
|
||||
|
||||
from fittrackee.workouts.utils.workouts import get_average_speed
|
||||
from fittrackee.workouts.utils.workouts import (
|
||||
get_average_speed,
|
||||
get_workout_datetime,
|
||||
)
|
||||
|
||||
utc_datetime = datetime(
|
||||
year=2022, month=6, day=11, hour=10, minute=23, second=00, tzinfo=pytz.utc
|
||||
)
|
||||
input_workout_dates = [
|
||||
utc_datetime,
|
||||
utc_datetime.replace(tzinfo=None),
|
||||
utc_datetime.replace(tzinfo=SimpleTZ('Z')),
|
||||
utc_datetime.astimezone(pytz.timezone('Europe/Paris')),
|
||||
utc_datetime.astimezone(pytz.timezone('America/Toronto')),
|
||||
'2022-06-11 12:23:00',
|
||||
]
|
||||
|
||||
|
||||
class TestWorkoutAverageSpeed:
|
||||
@ -30,3 +48,68 @@ class TestWorkoutAverageSpeed:
|
||||
assert get_average_speed(
|
||||
nb_workouts, total_average_speed, workout_average_speed
|
||||
) == mean(ave_speeds_list)
|
||||
|
||||
|
||||
class TestWorkoutGetWorkoutDatetime:
|
||||
@pytest.mark.parametrize('input_workout_date', input_workout_dates)
|
||||
def test_it_returns_naive_datetime(
|
||||
self, input_workout_date: Union[datetime, str]
|
||||
) -> None:
|
||||
naive_workout_date, _ = get_workout_datetime(
|
||||
workout_date=input_workout_date, user_timezone='Europe/Paris'
|
||||
)
|
||||
|
||||
assert naive_workout_date == datetime(
|
||||
year=2022, month=6, day=11, hour=10, minute=23, second=00
|
||||
)
|
||||
|
||||
def test_it_return_naive_datetime_when_no_user_timezone(self) -> None:
|
||||
naive_workout_date, _ = get_workout_datetime(
|
||||
workout_date='2022-06-11 12:23:00', user_timezone=None
|
||||
)
|
||||
|
||||
assert naive_workout_date == datetime(
|
||||
year=2022, month=6, day=11, hour=12, minute=23, second=00
|
||||
)
|
||||
|
||||
@pytest.mark.parametrize('input_workout_date', input_workout_dates)
|
||||
def test_it_returns_datetime_with_user_timezone(
|
||||
self, input_workout_date: Union[datetime, str]
|
||||
) -> None:
|
||||
timezone = 'Europe/Paris'
|
||||
|
||||
_, workout_date_with_tz = get_workout_datetime(
|
||||
input_workout_date, user_timezone=timezone, with_timezone=True
|
||||
)
|
||||
|
||||
assert workout_date_with_tz == datetime(
|
||||
year=2022,
|
||||
month=6,
|
||||
day=11,
|
||||
hour=10,
|
||||
minute=23,
|
||||
second=00,
|
||||
tzinfo=pytz.utc,
|
||||
).astimezone(pytz.timezone(timezone))
|
||||
|
||||
def test_it_does_not_return_datetime_with_user_timezone_when_no_user_tz(
|
||||
self,
|
||||
) -> None:
|
||||
_, workout_date_with_tz = get_workout_datetime(
|
||||
workout_date='2022-06-11 12:23:00',
|
||||
user_timezone=None,
|
||||
with_timezone=True,
|
||||
)
|
||||
|
||||
assert workout_date_with_tz is None
|
||||
|
||||
def test_it_does_not_return_datetime_with_user_timezone_when_with_timezone_to_false( # noqa
|
||||
self,
|
||||
) -> None:
|
||||
_, workout_date_with_tz = get_workout_datetime(
|
||||
workout_date='2022-06-11 12:23:00',
|
||||
user_timezone='Europe/Paris',
|
||||
with_timezone=False,
|
||||
)
|
||||
|
||||
assert workout_date_with_tz is None
|
||||
|
@ -969,7 +969,7 @@ class TestGetWorkoutsWithFiltersAndPagination(ApiTestCaseMixin):
|
||||
|
||||
|
||||
class TestGetWorkout(ApiTestCaseMixin):
|
||||
def test_it_gets_an_workout(
|
||||
def test_it_gets_a_workout(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -1105,7 +1105,7 @@ class TestGetWorkout(ApiTestCaseMixin):
|
||||
response, f'no gpx file for this workout (id: {workout_short_id})'
|
||||
)
|
||||
|
||||
def test_it_returns_500_on_getting_gpx_if_an_workout_has_invalid_gpx_pathname( # noqa
|
||||
def test_it_returns_500_on_getting_gpx_if_a_workout_has_invalid_gpx_pathname( # noqa
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -1125,7 +1125,7 @@ class TestGetWorkout(ApiTestCaseMixin):
|
||||
data = self.assert_500(response)
|
||||
assert 'data' not in data
|
||||
|
||||
def test_it_returns_500_on_getting_chart_data_if_an_workout_has_invalid_gpx_pathname( # noqa
|
||||
def test_it_returns_500_on_getting_chart_data_if_a_workout_has_invalid_gpx_pathname( # noqa
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
|
@ -2,7 +2,7 @@ import json
|
||||
import os
|
||||
from datetime import datetime
|
||||
from io import BytesIO
|
||||
from typing import Dict
|
||||
from typing import Dict, Optional
|
||||
from unittest.mock import Mock
|
||||
|
||||
import pytest
|
||||
@ -92,9 +92,7 @@ def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
assert data['data']['workouts'][0]['descent'] == 23.4
|
||||
assert data['data']['workouts'][0]['distance'] == 0.3
|
||||
assert data['data']['workouts'][0]['max_alt'] == 998.0
|
||||
assert (
|
||||
data['data']['workouts'][0]['max_speed'] is None
|
||||
) # not enough points
|
||||
assert data['data']['workouts'][0]['max_speed'] == 5.25
|
||||
assert data['data']['workouts'][0]['min_alt'] == 975.0
|
||||
assert data['data']['workouts'][0]['moving'] == '0:03:55'
|
||||
assert data['data']['workouts'][0]['pauses'] == '0:00:15'
|
||||
@ -114,7 +112,7 @@ def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
assert segment['descent'] == 11.0
|
||||
assert segment['distance'] == 0.113
|
||||
assert segment['max_alt'] == 998.0
|
||||
assert segment['max_speed'] is None
|
||||
assert segment['max_speed'] == 5.25
|
||||
assert segment['min_alt'] == 987.0
|
||||
assert segment['moving'] == '0:01:30'
|
||||
assert segment['pauses'] is None
|
||||
@ -128,28 +126,33 @@ def assert_workout_data_with_gpx_segments(data: Dict) -> None:
|
||||
assert segment['descent'] == 12.4
|
||||
assert segment['distance'] == 0.186
|
||||
assert segment['max_alt'] == 987.0
|
||||
assert segment['max_speed'] is None
|
||||
assert segment['max_speed'] == 5.12
|
||||
assert segment['min_alt'] == 975.0
|
||||
assert segment['moving'] == '0:02:25'
|
||||
assert segment['pauses'] is None
|
||||
|
||||
records = data['data']['workouts'][0]['records']
|
||||
assert len(records) == 3
|
||||
assert len(records) == 4
|
||||
assert records[0]['sport_id'] == 1
|
||||
assert records[0]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[0]['record_type'] == 'LD'
|
||||
assert records[0]['record_type'] == 'MS'
|
||||
assert records[0]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[0]['value'] == '0:03:55'
|
||||
assert records[0]['value'] == 5.25
|
||||
assert records[1]['sport_id'] == 1
|
||||
assert records[1]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[1]['record_type'] == 'FD'
|
||||
assert records[1]['record_type'] == 'LD'
|
||||
assert records[1]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[1]['value'] == 0.3
|
||||
assert records[1]['value'] == '0:03:55'
|
||||
assert records[2]['sport_id'] == 1
|
||||
assert records[2]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[2]['record_type'] == 'AS'
|
||||
assert records[2]['record_type'] == 'FD'
|
||||
assert records[2]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[2]['value'] == 4.59
|
||||
assert records[2]['value'] == 0.3
|
||||
assert records[3]['sport_id'] == 1
|
||||
assert records[3]['workout_id'] == data['data']['workouts'][0]['id']
|
||||
assert records[3]['record_type'] == 'AS'
|
||||
assert records[3]['workout_date'] == 'Tue, 13 Mar 2018 12:44:45 GMT'
|
||||
assert records[3]['value'] == 4.59
|
||||
|
||||
|
||||
def assert_workout_data_wo_gpx(data: Dict) -> None:
|
||||
@ -222,7 +225,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
|
||||
self.assert_401(response)
|
||||
|
||||
def test_it_adds_an_workout_with_gpx_file(
|
||||
def test_it_adds_a_workout_with_gpx_file(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -248,7 +251,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
assert 'just a workout' == data['data']['workouts'][0]['title']
|
||||
assert_workout_data_with_gpx(data)
|
||||
|
||||
def test_it_adds_an_workout_with_gpx_without_name(
|
||||
def test_it_adds_a_workout_with_gpx_without_name(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -281,7 +284,7 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
)
|
||||
assert_workout_data_with_gpx(data)
|
||||
|
||||
def test_it_adds_an_workout_with_gpx_without_name_timezone(
|
||||
def test_it_adds_a_workout_with_gpx_without_name_timezone(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -315,6 +318,41 @@ class TestPostWorkoutWithGpx(ApiTestCaseMixin, CallArgsMixin):
|
||||
)
|
||||
assert_workout_data_with_gpx(data)
|
||||
|
||||
@pytest.mark.parametrize('input_user_timezone', [None, 'Europe/Paris'])
|
||||
def test_it_adds_a_workout_with_gpx_with_offset(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
sport_1_cycling: Sport,
|
||||
gpx_file_with_offset: str,
|
||||
input_user_timezone: Optional[str],
|
||||
) -> None:
|
||||
user_1.timezone = input_user_timezone
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_1.email
|
||||
)
|
||||
|
||||
response = client.post(
|
||||
'/api/workouts',
|
||||
data=dict(
|
||||
file=(
|
||||
BytesIO(str.encode(gpx_file_with_offset)),
|
||||
'example.gpx',
|
||||
),
|
||||
data='{"sport_id": 1}',
|
||||
),
|
||||
headers=dict(
|
||||
content_type='multipart/form-data',
|
||||
Authorization=f'Bearer {auth_token}',
|
||||
),
|
||||
)
|
||||
|
||||
data = json.loads(response.data.decode())
|
||||
assert response.status_code == 201
|
||||
assert 'created' in data['status']
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert_workout_data_with_gpx(data)
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'input_description,input_notes',
|
||||
[
|
||||
@ -606,7 +644,7 @@ class TestPostWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
|
||||
self.assert_401(response)
|
||||
|
||||
def test_it_adds_an_workout_without_gpx(
|
||||
def test_it_adds_a_workout_without_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -953,12 +991,12 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
self.assert_500(response)
|
||||
|
||||
def test_it_gets_an_workout_created_with_gpx(
|
||||
def test_it_gets_a_workout_created_with_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
return self.workout_assertion(app, user_1, gpx_file, False)
|
||||
|
||||
def test_it_gets_an_workout_created_with_gpx_with_segments(
|
||||
def test_it_gets_a_workout_created_with_gpx_with_segments(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -969,7 +1007,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
|
||||
app, user_1, gpx_file_with_segments, True
|
||||
)
|
||||
|
||||
def test_it_gets_chart_data_for_an_workout_created_with_gpx(
|
||||
def test_it_gets_chart_data_for_a_workout_created_with_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -1000,7 +1038,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
|
||||
assert data['message'] == ''
|
||||
assert data['data']['chart_data'] != ''
|
||||
|
||||
def test_it_gets_segment_chart_data_for_an_workout_created_with_gpx(
|
||||
def test_it_gets_segment_chart_data_for_a_workout_created_with_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -1125,7 +1163,7 @@ class TestPostAndGetWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
|
||||
class TestPostAndGetWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
def test_it_add_and_gets_an_workout_wo_gpx(
|
||||
def test_it_add_and_gets_a_workout_wo_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -1158,7 +1196,7 @@ class TestPostAndGetWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert_workout_data_wo_gpx(data)
|
||||
|
||||
def test_it_adds_and_gets_an_workout_wo_gpx_notes(
|
||||
def test_it_adds_and_gets_a_workout_wo_gpx_notes(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
@ -1194,7 +1232,7 @@ class TestPostAndGetWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
|
||||
|
||||
class TestPostAndGetWorkoutUsingTimezones(ApiTestCaseMixin):
|
||||
def test_it_add_and_gets_an_workout_wo_gpx_with_timezone(
|
||||
def test_it_add_and_gets_a_workout_wo_gpx_with_timezone(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport
|
||||
) -> None:
|
||||
user_1.timezone = 'Europe/Paris'
|
||||
|
@ -9,7 +9,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
from .utils import get_random_short_id, post_a_workout
|
||||
|
||||
|
||||
def assert_workout_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
@ -56,7 +56,7 @@ def assert_workout_data_with_gpx(data: Dict, sport_id: int) -> None:
|
||||
|
||||
|
||||
class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
def test_it_updates_title_for_an_workout_with_gpx(
|
||||
def test_it_updates_title_for_a_workout_with_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -64,7 +64,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
@ -100,7 +100,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
@ -124,7 +124,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(
|
||||
token, workout_short_id = post_a_workout(
|
||||
app, gpx_file, notes=uuid4().hex
|
||||
)
|
||||
client = app.test_client()
|
||||
@ -142,7 +142,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert data['data']['workouts'][0]['notes'] == ''
|
||||
|
||||
def test_it_raises_403_when_editing_an_workout_from_different_user(
|
||||
def test_it_raises_403_when_editing_a_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -151,7 +151,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
_, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
@ -173,7 +173,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_2_running: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
@ -194,7 +194,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
def test_it_returns_400_if_payload_is_empty(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
@ -209,7 +209,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
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, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.patch(
|
||||
@ -223,7 +223,7 @@ class TestEditWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
|
||||
class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
def test_it_updates_an_workout_wo_gpx(
|
||||
def test_it_updates_a_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -364,7 +364,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
assert len(data['data']['workouts']) == 1
|
||||
assert data['data']['workouts'][0]['notes'] == ''
|
||||
|
||||
def test_returns_403_when_editing_an_workout_wo_gpx_from_different_user(
|
||||
def test_returns_403_when_editing_a_workout_wo_gpx_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -393,7 +393,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
|
||||
self.assert_403(response)
|
||||
|
||||
def test_it_updates_an_workout_wo_gpx_with_timezone(
|
||||
def test_it_updates_a_workout_wo_gpx_with_timezone(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1_paris: User,
|
||||
@ -468,7 +468,7 @@ class TestEditWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
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_workout_wo_gpx(
|
||||
def test_it_updates_only_sport_and_distance_a_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
|
@ -7,7 +7,7 @@ from fittrackee.users.models import User
|
||||
from fittrackee.workouts.models import Sport, Workout
|
||||
|
||||
from ..mixins import ApiTestCaseMixin
|
||||
from .utils import get_random_short_id, post_an_workout
|
||||
from .utils import get_random_short_id, post_a_workout
|
||||
|
||||
|
||||
def get_gpx_filepath(workout_id: int) -> str:
|
||||
@ -16,10 +16,10 @@ def get_gpx_filepath(workout_id: int) -> str:
|
||||
|
||||
|
||||
class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
def test_it_deletes_an_workout_with_gpx(
|
||||
def test_it_deletes_a_workout_with_gpx(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
|
||||
response = client.delete(
|
||||
@ -29,7 +29,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
assert response.status_code == 204
|
||||
|
||||
def test_it_returns_403_when_deleting_an_workout_from_different_user(
|
||||
def test_it_returns_403_when_deleting_a_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -37,7 +37,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
sport_1_cycling: Sport,
|
||||
gpx_file: str,
|
||||
) -> None:
|
||||
_, workout_short_id = post_an_workout(app, gpx_file)
|
||||
_, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client, auth_token = self.get_test_client_and_auth_token(
|
||||
app, user_2.email
|
||||
)
|
||||
@ -64,10 +64,10 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
data = self.assert_404(response)
|
||||
assert 'not found' in data['status']
|
||||
|
||||
def test_it_returns_500_when_deleting_an_workout_with_gpx_invalid_file(
|
||||
def test_it_returns_500_when_deleting_a_workout_with_gpx_invalid_file(
|
||||
self, app: Flask, user_1: User, sport_1_cycling: Sport, gpx_file: str
|
||||
) -> None:
|
||||
token, workout_short_id = post_an_workout(app, gpx_file)
|
||||
token, workout_short_id = post_a_workout(app, gpx_file)
|
||||
client = app.test_client()
|
||||
gpx_filepath = get_gpx_filepath(1)
|
||||
gpx_filepath = get_absolute_file_path(gpx_filepath)
|
||||
@ -82,7 +82,7 @@ class TestDeleteWorkoutWithGpx(ApiTestCaseMixin):
|
||||
|
||||
|
||||
class TestDeleteWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
def test_it_deletes_an_workout_wo_gpx(
|
||||
def test_it_deletes_a_workout_wo_gpx(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
@ -98,7 +98,7 @@ class TestDeleteWorkoutWithoutGpx(ApiTestCaseMixin):
|
||||
)
|
||||
assert response.status_code == 204
|
||||
|
||||
def test_it_returns_403_when_deleting_an_workout_from_different_user(
|
||||
def test_it_returns_403_when_deleting_a_workout_from_different_user(
|
||||
self,
|
||||
app: Flask,
|
||||
user_1: User,
|
||||
|
@ -12,7 +12,7 @@ def get_random_short_id() -> str:
|
||||
return encode_uuid(uuid4())
|
||||
|
||||
|
||||
def post_an_workout(
|
||||
def post_a_workout(
|
||||
app: Flask, gpx_file: str, notes: Optional[str] = None
|
||||
) -> Tuple[str, str]:
|
||||
client = app.test_client()
|
||||
|
Reference in New Issue
Block a user