API - add some tests on stop time calculation

This commit is contained in:
Sam 2022-07-13 08:26:05 +02:00
parent 701e4292a4
commit 1a43e4607a
2 changed files with 91 additions and 1 deletions

View File

@ -702,6 +702,62 @@ def gpx_file_with_segments() -> str:
)
@pytest.fixture()
def gpx_file_with_3_segments() -> str:
"""60 seconds between each segment"""
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>'
' <name>just a workout</name>'
' <trkseg>'
' <trkpt lat="44.68095" lon="6.07367">'
' <ele>998</ele>'
' <time>2018-03-13T12:44:50Z</time>'
' </trkpt>'
' <trkpt lat="44.68091" lon="6.07367">'
' <ele>998</ele>'
' <time>2018-03-13T12:44:55Z</time>'
' </trkpt>'
' <trkpt lat="44.6808" lon="6.07364">'
' <ele>994</ele>'
' <time>2018-03-13T12:45:00Z</time>'
' </trkpt>'
' </trkseg>'
' <trkseg>'
' <trkpt lat="44.67972" lon="6.07367">'
' <ele>987</ele>'
' <time>2018-03-13T12:46:00Z</time>'
' </trkpt>'
' <trkpt lat="44.67966" lon="6.07368">'
' <ele>987</ele>'
' <time>2018-03-13T12:46:05Z</time>'
' </trkpt>'
' <trkpt lat="44.67961" lon="6.0737">'
' <ele>986</ele>'
' <time>2018-03-13T12:46:10Z</time>'
' </trkpt>'
' </trkseg>'
' <trkseg>'
' <trkpt lat="44.67858" lon="6.07425">'
' <ele>980</ele>'
' <time>2018-03-13T12:47:10Z</time>'
' </trkpt>'
' <trkpt lat="44.67842" lon="6.07434">'
' <ele>979</ele>'
' <time>2018-03-13T12:47:15Z</time>'
' </trkpt>'
' <trkpt lat="44.67837" lon="6.07435">'
' <ele>979</ele>'
' <time>2018-03-13T12:47:20Z</time>'
' </trkpt>'
' </trkseg>'
' </trk>'
'</gpx>'
)
@pytest.fixture()
def gpx_file_storage(gpx_file: str) -> FileStorage:
return FileStorage(

View File

@ -1,3 +1,4 @@
from datetime import timedelta
from unittest.mock import call, patch
import pytest
@ -5,9 +6,10 @@ from flask import Flask
from gpxpy.gpx import IGNORE_TOP_SPEED_PERCENTILES, MovingData
from werkzeug.datastructures import FileStorage
from fittrackee.tests.utils import random_string
from fittrackee.users.models import User, UserSportPreference
from fittrackee.workouts.models import Sport
from fittrackee.workouts.utils.workouts import process_files
from fittrackee.workouts.utils.workouts import get_gpx_info, process_files
folders = {
'extract_dir': '/tmp/fitTrackee/uploads',
@ -96,3 +98,35 @@ class TestStoppedSpeedThreshold:
IGNORE_TOP_SPEED_PERCENTILES, # speed_extreemes_percentiles
True, # ignore_nonstandard_distances
)
class TestGetGpxInfoStopTime:
def test_stop_time_equals_to_0_when_gpx_file_contains_one_segment(
self, gpx_file: str
) -> None:
"""
stopped_speed_threshold to 0 to avoid calculated stopped time
in segments
"""
with patch('builtins.open', return_value=gpx_file):
gpx_data, _, _ = get_gpx_info(
gpx_file=random_string(), stopped_speed_threshold=0.0
)
assert gpx_data['stop_time'] == timedelta(seconds=0)
def test_stop_time_equals_to_stopped_time_sum_between_all_segments(
self, gpx_file_with_3_segments: str
) -> None:
"""
stopped_speed_threshold to 0 to avoid calculated stopped time
in segments
"""
with patch('builtins.open', return_value=gpx_file_with_3_segments):
gpx_data, _, _ = get_gpx_info(
gpx_file=random_string(), stopped_speed_threshold=0.0
)
assert gpx_data['stop_time'] == timedelta(seconds=120)