Skip to content

Commit

Permalink
HB2-85 add test for bad route and update docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric Hofstetter committed Oct 21, 2020
1 parent 84dd942 commit 707b27e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
13 changes: 12 additions & 1 deletion homebytwo/routes/models/track.py
Expand Up @@ -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

Expand Down
13 changes: 13 additions & 0 deletions homebytwo/routes/tests/test_route.py
Expand Up @@ -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(
Expand Down

0 comments on commit 707b27e

Please sign in to comment.