API - handle gpx files with offset
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user