Changeset c6219ed in OpenWorkouts-current for ow/tests/models/test_workout.py


Ignore:
Timestamp:
Jan 22, 2019, 12:21:51 AM (5 years ago)
Author:
Borja Lopez <borja@…>
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.
Message:

Merged patches from darcs

File:
1 edited

Legend:

Unmodified
Added
Removed
  • ow/tests/models/test_workout.py

    r02048a6 rc6219ed  
    1212from ow.models.root import OpenWorkouts
    1313from ow.utilities import create_blob
     14
     15from ow.tests.helpers import join
    1416
    1517
     
    210212        # workout still not saved to the db
    211213        workout.tracking_file = Mock()
    212         workout.tracking_file._p_blob_uncommitted = '/tmp/blobtempfile'
    213         workout.tracking_file._p_blob_committed = None
     214        workout.tracking_file._uncommitted.return_value = '/tmp/blobtempfile'
     215        workout.tracking_file.committed.return_value = None
    214216        assert workout.tracking_file_path == '/tmp/blobtempfile'
    215         workout.tracking_file._p_blob_uncommitted = None
    216         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'
    217219        assert workout.tracking_file_path == '/var/db/blobs/blobfile'
    218220
     
    223225        # workout still not saved to the db
    224226        workout.fit_file = Mock()
    225         workout.fit_file._p_blob_uncommitted = '/tmp/blobtempfile'
    226         workout.fit_file._p_blob_committed = None
     227        workout.fit_file._uncommitted.return_value = '/tmp/blobtempfile'
     228        workout.fit_file.committed.return_value = None
    227229        assert workout.fit_file_path == '/tmp/blobtempfile'
    228         workout.fit_file._p_blob_uncommitted = None
    229         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'
    230232        assert workout.fit_file_path == '/var/db/blobs/blobfile'
    231233
     
    514516        workout = root['john']['1']
    515517        # without tracking file
    516         assert workout.has_tracking_file is False
     518        assert not workout.has_tracking_file
    517519        # with tracking file
    518520        workout.tracking_file = 'faked tracking file'
    519         assert workout.has_tracking_file is True
     521        assert workout.has_tracking_file
    520522
    521523    def test_has_gpx(self, root):
    522524        workout = root['john']['1']
    523525        # without tracking file
    524         assert workout.has_gpx is False
     526        assert not workout.has_gpx
    525527        workout.tracking_filetype = 'fit'
    526         assert workout.has_gpx is False
     528        assert not workout.has_gpx
    527529        # with non-gpx tracking file
    528530        workout.tracking_file = 'faked tracking file'
    529531        workout.tracking_filetype = 'fit'
    530         assert workout.has_gpx is False
     532        assert not workout.has_gpx
    531533        # with gpx tracking file
    532534        workout.tracking_file = 'faked tracking file'
    533535        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.