Changeset c6219ed in OpenWorkouts-current for ow/tests/models/test_workout.py
- Timestamp:
- Jan 22, 2019, 12:21:51 AM (5 years ago)
- Branches:
- current, feature/docs, master
- Children:
- 26220ba, 2d2eb0d
- Parents:
- 02048a6 (diff), be40b02 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
ow/tests/models/test_workout.py
r02048a6 rc6219ed 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 … … 210 212 # workout still not saved to the db 211 213 workout.tracking_file = Mock() 212 workout.tracking_file._ p_blob_uncommitted= '/tmp/blobtempfile'213 workout.tracking_file. _p_blob_committed= None214 workout.tracking_file._uncommitted.return_value = '/tmp/blobtempfile' 215 workout.tracking_file.committed.return_value = None 214 216 assert workout.tracking_file_path == '/tmp/blobtempfile' 215 workout.tracking_file._ p_blob_uncommitted= None216 workout.tracking_file. _p_blob_committed= '/var/db/blobs/blobfile'217 workout.tracking_file._uncommitted.return_value = None 218 workout.tracking_file.committed.return_value = '/var/db/blobs/blobfile' 217 219 assert workout.tracking_file_path == '/var/db/blobs/blobfile' 218 220 … … 223 225 # workout still not saved to the db 224 226 workout.fit_file = Mock() 225 workout.fit_file._ p_blob_uncommitted= '/tmp/blobtempfile'226 workout.fit_file. _p_blob_committed= None227 workout.fit_file._uncommitted.return_value = '/tmp/blobtempfile' 228 workout.fit_file.committed.return_value = None 227 229 assert workout.fit_file_path == '/tmp/blobtempfile' 228 workout.fit_file._ p_blob_uncommitted= None229 workout.fit_file. _p_blob_committed= '/var/db/blobs/blobfile'230 workout.fit_file._uncommitted.return_value = None 231 workout.fit_file.committed.return_value = '/var/db/blobs/blobfile' 230 232 assert workout.fit_file_path == '/var/db/blobs/blobfile' 231 233 … … 514 516 workout = root['john']['1'] 515 517 # without tracking file 516 assert workout.has_tracking_file is False518 assert not workout.has_tracking_file 517 519 # with tracking file 518 520 workout.tracking_file = 'faked tracking file' 519 assert workout.has_tracking_file is True521 assert workout.has_tracking_file 520 522 521 523 def test_has_gpx(self, root): 522 524 workout = root['john']['1'] 523 525 # without tracking file 524 assert workout.has_gpx is False526 assert not workout.has_gpx 525 527 workout.tracking_filetype = 'fit' 526 assert workout.has_gpx is False528 assert not workout.has_gpx 527 529 # with non-gpx tracking file 528 530 workout.tracking_file = 'faked tracking file' 529 531 workout.tracking_filetype = 'fit' 530 assert workout.has_gpx is False532 assert not workout.has_gpx 531 533 # with gpx tracking file 532 534 workout.tracking_file = 'faked tracking file' 533 535 workout.tracking_filetype = 'gpx' 534 assert workout.has_gpx is True 536 assert workout.has_gpx 537 538 def test_has_fit(self, root): 539 workout = root['john']['1'] 540 # without tracking file 541 assert not workout.has_fit 542 # tracking_file is a fit, this should not happen, as uploading a fit 543 # puts the fit file into .fit_file and generates a gpx for 544 # .tracking_file 545 workout.tracking_file = 'faked tracking file' 546 workout.tracking_filetype = 'fit' 547 assert not workout.has_fit 548 # now, having a fit file returns true 549 workout.fit_file = 'faked fit file' 550 assert workout.has_fit 551 # no matter what we have in tracking_file 552 workout.tracking_filetype = 'gpx' 553 assert workout.has_fit 554 workout.tracking_file = None 555 workout.tracking_filetype = None 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.