Changeset b3374f6 in OpenWorkouts-current for ow/tests/models/test_workout.py
- Timestamp:
- Feb 12, 2019, 5:55:33 PM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- c999b73e
- Parents:
- f713dbc
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/models/test_workout.py
rf713dbc rb3374f6 7 7 import pytest 8 8 from pyramid.security import Allow, Everyone, Deny, ALL_PERMISSIONS 9 from pyramid.testing import DummyRequest10 9 11 10 from ow.models.workout import Workout … … 573 572 assert workout.has_fit 574 573 574 def test_map_screenshot_name(self, root): 575 workout = root['john']['1'] 576 assert workout.map_screenshot_name == ( 577 str(root['john'].uid) + '/' + str(workout.workout_id) + '.png') 578 579 def test_map_screenshot_path(self, root): 580 workout = root['john']['1'] 581 assert workout.map_screenshot_path.endswith( 582 'static/maps/' + workout.map_screenshot_name) 583 575 584 @patch('ow.models.workout.os') 576 @patch('ow.models.workout.save_map_screenshot') 577 def test_map_screenshot_no_gpx(self, sms, os, root): 578 workout = root['john']['1'] 579 request = DummyRequest() 580 assert workout.map_screenshot(request) is None 581 assert not os.path.abspath.called 582 assert not os.path.dirname.called 585 def test_map_screenshot_no_gpx(self, os, root): 586 workout = root['john']['1'] 587 assert workout.map_screenshot is None 583 588 assert not os.path.join.called 584 589 assert not os.path.exists.called 585 assert not sms.called586 590 587 591 @patch('ow.models.workout.os') 588 @patch('ow.models.workout.save_map_screenshot') 589 def test_map_screenshot_save(self, sms, os, root): 590 """ 591 A workout with a tracking file has no map screenshot, one is 592 saved to the filesystem. 593 This test simply asserts the calls to the separate methods that 594 look for existing screenshots and save a new one 595 """ 596 os.path.abspath.return_value = 'current_dir' 597 os.path.join.side_effect = join 598 # This forces the "save screenshot" code to be run 592 def test_map_screenshot_no_shot(self, os, root): 593 """ 594 A workout with a tracking file has no map screenshot 595 """ 596 # This says "no screenshot found" 599 597 os.path.exists.return_value = False 600 598 … … 603 601 workout.tracking_filetype = 'gpx' 604 602 605 uid = str(root['john'].uid) 606 request = DummyRequest() 607 # dummyrequest can't resolve static assets without adding a lot 608 # of boilerplate, no need for that here 609 request.static_url = Mock() 610 request.static_url.return_value = 'ow:/static/maps/' + uid + '/1.png' 611 res = workout.map_screenshot(request) 612 assert res == '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 == 3 616 assert os.path.exists.called 617 sms.assert_called_once_with(workout, request) 603 assert workout.map_screenshot is None 604 assert os.path.join.called 605 os.path.exists.assert_called_once_with(workout.map_screenshot_path) 618 606 619 607 @patch('ow.models.workout.os') 620 @patch('ow.models.workout.save_map_screenshot') 621 def test_map_screenshot_do_not_save(self, sms, os, root): 608 def test_map_screenshot_has_shot(self, os, root): 622 609 """ 623 610 A workout with a tracking file has a map screenshot, the path to that 624 611 is returned without doing anything else 625 612 """ 626 os.path.abspath.return_value = 'current_dir' 613 # This says "yeah, we have a screenshot" 614 os.path.exists.return_value = True 615 os.path.abspath.return_value = '/' 627 616 os.path.join.side_effect = join 628 # This forces the "save screenshot" code NOT to be run629 os.path.eisxts.return_value = True630 617 631 618 workout = root['john']['1'] 632 619 workout.tracking_file = 'faked gpx file' 633 620 workout.tracking_filetype = 'gpx' 634 635 621 uid = str(root['john'].uid) 636 request = DummyRequest() 637 # dummyrequest can't resolve static assets without adding a lot 638 # of boilerplate, no need for that here 639 request.static_url = Mock() 640 request.static_url.return_value = 'ow:/static/maps/' + uid + '/1.png' 641 res = workout.map_screenshot(request) 642 assert res == 'ow:/static/maps/' + uid + '/1.png' 643 assert os.path.abspath.called 644 assert os.path.dirname.called 645 assert os.path.join.call_count == 3 646 assert os.path.exists.called 647 assert not sms.called 622 assert workout.map_screenshot == 'ow:/static/maps/' + uid + '/1.png' 623 os.path.exists.assert_called_once_with(workout.map_screenshot_path) 624 assert os.path.join.called
Note: See TracChangeset
for help on using the changeset viewer.