Changeset 55470f9 in OpenWorkouts-current for ow/tests/views/test_user.py


Ignore:
Timestamp:
Feb 8, 2019, 1:41:41 PM (5 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current, feature/docs, master
Children:
6edc367, 78af3d1
Parents:
c9991fed
Message:

Fixed some tests broken during the last code changes.
Fixed a bug in the calculations of the totals for the profile page
(we weren't taking in account possible None values for distance,
duration and specially elevation/uphill)

File:
1 edited

Legend:

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

    rc9991fed r55470f9  
    11import os
    22import json
     3from decimal import Decimal
    34from datetime import datetime, timedelta, timezone
    45from shutil import copyfileobj
     
    269270        # profile page for the current day (no workouts avalable)
    270271        response = user_views.profile(john, request)
    271         assert len(response.keys()) == 3
     272        assert len(response.keys()) == 4
    272273        current_month = datetime.now(timezone.utc).strftime('%Y-%m')
    273274        assert response['current_month'] == current_month
    274275        assert response['current_week'] is None
    275276        assert response['workouts'] == []
     277        assert response['totals'] == {
     278            'distance': Decimal(0),
     279            'time': timedelta(0),
     280            'elevation': Decimal(0)
     281        }
    276282        # profile page for a previous date, that has workouts
    277283        request.GET['year'] = 2015
    278         request.GET['month'] = 8
     284        request.GET['month'] = 6
    279285        response = user_views.profile(john, request)
    280         assert len(response.keys()) == 3
    281         assert response['current_month'] == '2015-08'
     286        assert len(response.keys()) == 4
     287        assert response['current_month'] == '2015-06'
    282288        assert response['current_week'] is None
    283         assert response['workouts'] == john.workouts(2015, 8)
     289        workouts = john.workouts(2015, 6)
     290        assert response['workouts'] == workouts
     291        assert response['totals'] == {
     292            'distance': workouts[0].distance,
     293            'time': workouts[0].duration,
     294            'elevation': Decimal(0)
     295        }
    284296        # same, passing a week, first on a week without workouts
    285297        request.GET['year'] = 2015
    286         request.GET['month'] = 8
     298        request.GET['month'] = 6
    287299        request.GET['week'] = 25
    288300        response = user_views.profile(john, request)
    289         assert len(response.keys()) == 3
    290         assert response['current_month'] == '2015-08'
    291         assert response['current_week'] is 25
     301        assert len(response.keys()) == 4
     302        assert response['current_month'] == '2015-06'
     303        assert response['current_week'] == 25
    292304        assert response['workouts'] == []
    293         # now in a week with workoutss
     305        assert response['totals'] == {
     306            'distance': Decimal(0),
     307            'time': timedelta(0),
     308            'elevation': Decimal(0)
     309        }
     310        # now in a week with workouts
    294311        request.GET['year'] = 2015
    295         request.GET['month'] = 8
     312        request.GET['month'] = 6
    296313        request.GET['week'] = 26
    297314        response = user_views.profile(john, request)
    298         assert len(response.keys()) == 3
    299         assert response['current_month'] == '2015-08'
    300         assert response['current_week'] is 26
    301         assert response['workouts'] == john.workouts(2015, 8)
     315        assert len(response.keys()) == 4
     316        assert response['current_month'] == '2015-06'
     317        assert response['current_week'] == 26
     318        workouts = john.workouts(2015, 6)
     319        assert response['workouts'] == workouts
     320        assert response['totals'] == {
     321            'distance': workouts[0].distance,
     322            'time': workouts[0].duration,
     323            'elevation': Decimal(0)
     324        }
    302325
    303326    def test_login_get(self, dummy_request):
Note: See TracChangeset for help on using the changeset viewer.