From 707b27e5c01d23d4ac990b4a49c7129c23aef8d7 Mon Sep 17 00:00:00 2001 From: Cedric Hofstetter Date: Wed, 21 Oct 2020 10:55:50 +0300 Subject: [PATCH] HB2-85 add test for bad route and update docstring --- homebytwo/routes/models/track.py | 13 ++++++++++++- homebytwo/routes/tests/test_route.py | 13 +++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/homebytwo/routes/models/track.py b/homebytwo/routes/models/track.py index 85d77c13..3ca8e829 100644 --- a/homebytwo/routes/models/track.py +++ b/homebytwo/routes/models/track.py @@ -171,7 +171,18 @@ def update_permanent_track_data( self, min_step_distance=1, max_gradient=100, commit=True, force=False ): """ - calculate unvarying data columns and save them + make sure all unvarying data columns required for schedule calculation + are available and calculate missing ones. + + :param min_step_distance: minimum distance in m to keep between each point + :param max_gradient: maximum gradient to keep when cleaning rows + :param commit: save the instance to the database after update + :param force: recalculates columns even if they are already present + + :returns: None + :raises ValueError: if the number of coords in the track geometry + is not equal to the number of rows in data or if the cleaned data columns + are left with only one row. """ track_data_updated = False diff --git a/homebytwo/routes/tests/test_route.py b/homebytwo/routes/tests/test_route.py index 71fe7e74..7c1ec339 100644 --- a/homebytwo/routes/tests/test_route.py +++ b/homebytwo/routes/tests/test_route.py @@ -839,6 +839,19 @@ def test_update_permanent_track_data(athlete): assert len(saved_route.data.distance) == len(saved_route.geom) +def test_update_permanent_track_data_bad_route(): + data = DataFrame( + { + "distance": list(range(10)), + "altitude": list(range(10)), + } + ) + geom = LineString([(lng, 0) for lng in range(20)]) + route = RouteFactory.build(data=data, geom=geom) + with pytest.raises(ValueError): + route.update_permanent_track_data(commit=False) + + def test_calculate_projected_time_schedule(athlete): route = RouteFactory() activity_performance = ActivityPerformanceFactory(