Changeset 0dedfbe in OpenWorkouts-current for ow/tests/models
- Timestamp:
- Apr 22, 2019, 10:47:55 PM (5 years ago)
- Branches:
- current
- Children:
- a6fa857
- Parents:
- 42baca4
- Location:
- ow/tests/models
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/models/test_root.py
r42baca4 r0dedfbe 2 2 from unittest.mock import Mock 3 3 from datetime import datetime, timedelta, timezone 4 from decimal import Decimal 4 5 5 6 import pytest … … 175 176 john.add_workout(workout) 176 177 assert root.sports_json == json.dumps(["cycling", "running"]) 178 179 def test_get_workout_by_hash(self, root, john): 180 # non existant hash 181 found = root.get_workout_by_hash('non-existant-hash') 182 assert found is None 183 # existing workout 184 workout = root[str(john.uid)]['1'] 185 found = root.get_workout_by_hash(workout.hashed) 186 assert found == workout 187 # a workout that was not added to the system 188 workout = Workout( 189 start_time=datetime.now(timezone.utc), 190 duration=timedelta(seconds=3600), 191 distance=Decimal(30) 192 ) 193 found = root.get_workout_by_hash(workout.hashed) 194 assert found is None -
ow/tests/models/test_workout.py
r42baca4 r0dedfbe 143 143 workout.distance = 44.44444444 144 144 assert workout.rounded_distance == 44.44 145 146 def test_hashed(self, root): 147 # first test a workout that is attached to a user 148 workout = root['john']['1'] 149 assert workout.hashed == ( 150 str(workout.owner.uid) + 151 workout.start.strftime('%Y%m%d%H%M%S') + 152 str(workout.duration.seconds) + 153 str(workout.distance) 154 ) 155 # now a workout that is not (no owner info) 156 workout = Workout( 157 start_time=datetime.now(timezone.utc), 158 duration=timedelta(seconds=3600), 159 distance=Decimal(30) 160 ) 161 assert workout.hashed == ( 162 workout.start.strftime('%Y%m%d%H%M%S') + 163 str(workout.duration.seconds) + 164 str(workout.distance) 165 ) 166 # now an empty workout... 167 workout = Workout() 168 with pytest.raises(AttributeError): 169 assert workout.hashed == ( 170 workout.start.strftime('%Y%m%d%H%M%S') + 171 str(workout.duration.seconds) + 172 str(workout.distance) 173 ) 145 174 146 175 def test_trimmed_notes(self):
Note: See TracChangeset
for help on using the changeset viewer.