Changeset 2d91474 in OpenWorkouts-current for ow/tests/models/test_user.py


Ignore:
Timestamp:
Jan 15, 2019, 10:13:57 PM (5 years ago)
Author:
borja <borja@…>
Branches:
current, feature/docs, master
Children:
0c18869
Parents:
9bee49d
Message:

(#23) - Show workouts in the dashboard with date filtering

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/tests/models/test_user.py

    r9bee49d r2d91474  
     1from datetime import datetime, timedelta, timezone
     2
    13import pytest
    24from pyramid.security import Allow
     
    6870        assert list(root['john'].workout_ids()) == ['1', '2', '3']
    6971        assert root['john'].num_workouts == len(workouts)
     72
     73    def test_activity_dates_tree(self, root):
     74        # first an empty test
     75        assert root['john'].activity_dates_tree == {}
     76        # now add a cycling workout in a given date (25/11/2018)
     77        workout = Workout(
     78            start=datetime(2018, 11, 25, 10, 00, tzinfo=timezone.utc),
     79            duration=timedelta(minutes=(60*4)),
     80            distance=115,
     81            sport='cycling')
     82        root['john'].add_workout(workout)
     83        assert root['john'].activity_dates_tree == {
     84            2018: {11: {'cycling': 1}}
     85        }
     86        # add a running workout on the same date
     87        workout = Workout(
     88            start=datetime(2018, 11, 25, 16, 30, tzinfo=timezone.utc),
     89            duration=timedelta(minutes=60),
     90            distance=12,
     91            sport='running')
     92        root['john'].add_workout(workout)
     93        assert root['john'].activity_dates_tree == {
     94            2018: {11: {'cycling': 1, 'running': 1}}
     95        }
     96        # add a swimming workout on a different date, same year
     97        workout = Workout(
     98            start=datetime(2018, 8, 15, 11, 30, tzinfo=timezone.utc),
     99            duration=timedelta(minutes=30),
     100            distance=2,
     101            sport='swimming')
     102        root['john'].add_workout(workout)
     103        assert root['john'].activity_dates_tree == {
     104            2018: {8: {'swimming': 1},
     105                   11: {'cycling': 1, 'running': 1}}
     106        }
     107        # now add some more cycling in a different year
     108        # add a swimming workout on a different date, same year
     109        workout = Workout(
     110            start=datetime(2017, 4, 15, 15, 00, tzinfo=timezone.utc),
     111            duration=timedelta(minutes=(60*3)),
     112            distance=78,
     113            sport='cycling')
     114        root['john'].add_workout(workout)
     115        assert root['john'].activity_dates_tree == {
     116            2017: {4: {'cycling': 1}},
     117            2018: {8: {'swimming': 1},
     118                   11: {'cycling': 1, 'running': 1}}
     119        }
Note: See TracChangeset for help on using the changeset viewer.