Changeset e52a502 in OpenWorkouts-current
- Timestamp:
- Apr 19, 2019, 5:03:49 PM (5 years ago)
- Branches:
- current
- Children:
- 42baca4
- Parents:
- 39dc0a6
- Location:
- ow
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/views/test_workout.py
r39dc0a6 re52a502 5 5 from cgi import FieldStorage 6 6 from unittest.mock import Mock, patch, PropertyMock 7 from decimal import Decimal 7 8 8 9 import pytest … … 131 132 # no title, no sport, we generate a title based on when the 132 133 # workout started 133 ({'title': None, 'sport': None}, 'Morning workout'), 134 ({'title': None, 'sport': None}, 135 {'title': 'Morning workout', 136 'distance': 10}), 134 137 # no title, sport given, we use the sport too in the automatically 135 138 # generated title 136 ({'title': None, 'sport': 'cycling'}, 'Morning cycling workout'), 139 ({'title': None, 'sport': 'cycling'}, 140 {'title': 'Morning cycling workout', 141 'distance': 10}), 137 142 # 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}), 139 146 # 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}), 141 150 ] 142 151 … … 158 167 assert response.location.endswith('/2/') 159 168 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']) 161 172 162 173 def test_add_workout_get(self, dummy_request): -
ow/views/workout.py
r39dc0a6 re52a502 41 41 # "bind" to the object, we do calculate both the full duration in 42 42 # 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 43 46 excluded = ['duration_hours', 'duration_minutes', 'duration_seconds', 44 'start_date', 'start_time' ]47 'start_date', 'start_time', 'distance'] 45 48 workout = form.bind(Workout(), exclude=excluded) 46 49 duration = timedelta(hours=form.data['duration_hours'], … … 60 63 workout.title += ' ' + workout.sport 61 64 workout.title += ' ' + _('workout') 65 workout.distance = Decimal(form.data['distance']) 62 66 context.add_workout(workout) 63 67 return HTTPFound(location=request.resource_url(workout))
Note: See TracChangeset
for help on using the changeset viewer.