Changeset ceae158 in OpenWorkouts-current for ow/tests/models/test_workout.py
- Timestamp:
- Jan 21, 2019, 10:32:17 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- d1c4782
- Parents:
- b22a9d2
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/models/test_workout.py
rb22a9d2 rceae158 12 12 from ow.models.root import OpenWorkouts 13 13 from ow.utilities import create_blob 14 15 from ow.tests.helpers import join 14 16 15 17 … … 553 555 workout.tracking_filetype = None 554 556 assert workout.has_fit 557 558 @patch('ow.models.workout.os') 559 @patch('ow.models.workout.save_map_screenshot') 560 def test_map_screenshot_no_gpx(self, sms, os, root): 561 workout = root['john']['1'] 562 assert workout.map_screenshot is None 563 assert not os.path.abspath.called 564 assert not os.path.dirname.called 565 assert not os.path.join.called 566 assert not os.path.exists.called 567 assert not sms.called 568 569 @patch('ow.models.workout.os') 570 @patch('ow.models.workout.save_map_screenshot') 571 def test_map_screenshot_save(self, sms, os, root): 572 """ 573 A workout with a tracking file has no map screenshot, one is 574 saved to the filesystem. 575 This test simply asserts the calls to the separate methods that 576 look for existing screenshots and save a new one 577 """ 578 os.path.abspath.return_value = 'current_dir' 579 os.path.join.side_effect = join 580 # This forces the "save screenshot" code to be run 581 os.path.exists.return_value = False 582 583 workout = root['john']['1'] 584 workout.tracking_file = 'faked gpx file' 585 workout.tracking_filetype = 'gpx' 586 587 uid = str(root['john'].uid) 588 assert workout.map_screenshot == 'ow:/static/maps/' + uid + '/1.png' 589 assert os.path.abspath.called 590 assert os.path.dirname.called 591 assert os.path.join.call_count == 2 592 assert os.path.exists.called 593 sms.assert_called_once_with(workout) 594 595 @patch('ow.models.workout.os') 596 @patch('ow.models.workout.save_map_screenshot') 597 def test_map_screenshot_do_not_save(self, sms, os, root): 598 """ 599 A workout with a tracking file has a map screenshot, the path to that 600 is returned without doing anything else 601 """ 602 os.path.abspath.return_value = 'current_dir' 603 os.path.join.side_effect = join 604 # This forces the "save screenshot" code NOT to be run 605 os.path.exists.return_value = True 606 607 workout = root['john']['1'] 608 workout.tracking_file = 'faked gpx file' 609 workout.tracking_filetype = 'gpx' 610 611 uid = str(root['john'].uid) 612 assert workout.map_screenshot == 'ow:/static/maps/' + uid + '/1.png' 613 assert os.path.abspath.called 614 assert os.path.dirname.called 615 assert os.path.join.call_count == 2 616 assert os.path.exists.called 617 assert not sms.called
Note: See TracChangeset
for help on using the changeset viewer.