Changeset e52a502 in OpenWorkouts-current


Ignore:
Timestamp:
Apr 19, 2019, 5:03:49 PM (4 years ago)
Author:
Borja Lopez <borja@…>
Branches:
current
Children:
42baca4
Parents:
39dc0a6
Message:

(#73) Fixed broken "add workout manually" when provided with a distance value
with decimals.

Location:
ow
Files:
2 edited

Legend:

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

    r39dc0a6 re52a502  
    55from cgi import FieldStorage
    66from unittest.mock import Mock, patch, PropertyMock
     7from decimal import Decimal
    78
    89import pytest
     
    131132        # no title, no sport, we generate a title based on when the
    132133        # workout started
    133         ({'title': None, 'sport': None}, 'Morning workout'),
     134        ({'title': None, 'sport': None},
     135         {'title': 'Morning workout',
     136          'distance': 10}),
    134137        # no title, sport given, we use the sport too in the automatically
    135138        # generated title
    136         ({'title': None, 'sport': 'cycling'}, 'Morning cycling workout'),
     139        ({'title': None, 'sport': 'cycling'},
     140         {'title': 'Morning cycling workout',
     141          'distance': 10}),
    137142        # title given, no sport, we use the provided title
    138         ({'title': 'Example workout', 'sport': None}, 'Example workout'),
     143        ({'title': 'Example workout', 'sport': None},
     144         {'title': 'Example workout',
     145          'distance': 10}),
    139146        # title given, sport too, we use the provided title
    140         ({'title': 'Example workout', 'sport': 'cycling'}, 'Example workout'),
     147        ({'title': 'Example workout', 'sport': 'cycling'},
     148         {'title': 'Example workout',
     149          'distance': 10}),
    141150    ]
    142151
     
    158167        assert response.location.endswith('/2/')
    159168        assert len(user.workouts()) == 2
    160         assert user['2'].title == expected
     169        assert user['2'].title == expected['title']
     170        assert isinstance(user['2'].distance, Decimal)
     171        assert user['2'].distance == Decimal(expected['distance'])
    161172
    162173    def test_add_workout_get(self, dummy_request):
  • ow/views/workout.py

    r39dc0a6 re52a502  
    4141        # "bind" to the object, we do calculate both the full duration in
    4242        # seconds and the full datetime "start" and we save that
     43        #
     44        # exclude also the distance field, we have to convert to decimal
     45        # before adding it
    4346        excluded = ['duration_hours', 'duration_minutes', 'duration_seconds',
    44                     'start_date', 'start_time']
     47                    'start_date', 'start_time', 'distance']
    4548        workout = form.bind(Workout(), exclude=excluded)
    4649        duration = timedelta(hours=form.data['duration_hours'],
     
    6063                workout.title += ' ' + workout.sport
    6164            workout.title += ' ' + _('workout')
     65        workout.distance = Decimal(form.data['distance'])
    6266        context.add_workout(workout)
    6367        return HTTPFound(location=request.resource_url(workout))
Note: See TracChangeset for help on using the changeset viewer.