diff --git a/activities/gps/endomondo.py b/activities/gps/endomondo.py index edc2b74..7900f2c 100644 --- a/activities/gps/endomondo.py +++ b/activities/gps/endomondo.py @@ -4,6 +4,7 @@ from training import models from . import gpx +from . import gps_workout @transaction.atomic def _import_endomondo_workout(user, endomondo_workout): diff --git a/tests/test_client.py b/tests/test_client.py index ffdac58..49e72ce 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -231,6 +231,37 @@ def test_import_from_endomondo_no_workouts(self): statistics = self._get_statistics_from_dashboard() self.assertEqual(0, len(statistics.previous_workouts())) + def test_import_many_workouts_from_endomondo(self): + + def make_endomondo_workout(i): + + class EndomondoWorkout: + pass + + workout = EndomondoWorkout() + workout.id = i + workout.sport = "running" + workout.distance = 10 + workout.start_time = time(2016, 1, 1, 0, 0, 0) + workout.duration = datetime.timedelta(seconds=i) + workout.points = [] + + return workout + + with patch('endoapi.endomondo.Endomondo', autospec=True) as endomondo: + endomondo.return_value = Mock() + endomondo.return_value.token = 'token' + + self.post('/gps/endomondo/', {'email': 'legan@com.pl', 'password': 'haslo'}) + + endomondo.return_value.fetch.return_value = [make_endomondo_workout(i) for i in range(10)] + self.get('/gps/synchronize_endomondo_ajax/') + + endomondo.return_value.fetch.assert_called_once_with(max_results=10, before=None, after=None) + + statistics = self._get_statistics_from_dashboard() + self.assertEqual(10, len(statistics.previous_workouts())) + def _find_statistics_field(self, name, field): statistics = self._get_statistics_from_dashboard() workout_statistics = statistics.workout_statistics(name)