Changeset c6219ed in OpenWorkouts-current for ow/tests/test_utilities.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/test_utilities.py
r02048a6 rc6219ed 1 1 import os 2 from datetime import timedelta 3 from unittest.mock import patch 2 4 from pyexpat import ExpatError 3 5 from xml.dom.minidom import Element 4 6 5 7 import pytest 8 9 from ow.models.root import OpenWorkouts 10 from ow.models.user import User 11 from ow.models.workout import Workout 6 12 7 13 from ow.utilities import ( … … 16 22 mps_to_kmph, 17 23 kmph_to_mps, 24 save_map_screenshot 18 25 ) 19 26 27 from ow.tests.helpers import join 28 20 29 21 30 class TestUtilities(object): 31 32 @pytest.fixture 33 def john(self): 34 john = User(firstname='John', lastname='Doe', 35 email='john.doe@example.net') 36 john.password = 's3cr3t' 37 return john 38 39 @pytest.fixture 40 def root(self, john): 41 root = OpenWorkouts() 42 root.add_user(john) 43 john['1'] = Workout( 44 duration=timedelta(minutes=60), 45 distance=30 46 ) 47 return root 22 48 23 49 def test_slugify(self): … … 54 80 def test_kmph_to_mps(self): 55 81 assert kmph_to_mps(30) == 30 * 0.277778 82 83 @patch('ow.utilities.os') 84 @patch('ow.utilities.subprocess') 85 def test_save_map_screenshot_no_gpx(self, subprocess, os, root, john): 86 saved = save_map_screenshot(john['1']) 87 assert not saved 88 assert not os.path.abspath.called 89 assert not os.path.dirname.called 90 assert not os.path.join.called 91 assert not os.path.exists.called 92 assert not os.makedirs.called 93 assert not subprocess.run.called 94 # even having a fit tracking file, nothing is done 95 john['1'].tracking_file = 'faked fit file' 96 john['1'].tracking_filetype = 'fit' 97 saved = save_map_screenshot(john['1']) 98 assert not saved 99 assert not os.path.abspath.called 100 assert not os.path.dirname.called 101 assert not os.path.join.called 102 assert not os.path.exists.called 103 assert not os.makedirs.called 104 assert not subprocess.run.called 105 106 @patch('ow.utilities.os') 107 @patch('ow.utilities.subprocess') 108 def test_save_map_screenshot_with_gpx(self, subprocess, os, root, john): 109 os.path.abspath.return_value = 'current_dir' 110 os.path.join.side_effect = join 111 # This mimics what happens when the directory for this user map 112 # screenshots does not exist, which means we don'have to create one 113 # (calling os.makedirs) 114 os.path.exists.return_value = False 115 116 john['1'].tracking_file = 'faked gpx content' 117 john['1'].tracking_filetype = 'gpx' 118 saved = save_map_screenshot(john['1']) 119 assert saved 120 os.path.abspath.assert_called_once 121 assert os.path.dirname.called 122 assert os.path.join.call_count == 3 123 assert os.path.exists.called 124 assert os.makedirs.called 125 subprocess.run.assert_called_once 126 127 @patch('ow.utilities.os') 128 @patch('ow.utilities.subprocess') 129 def test_save_map_screenshot_with_gpx_makedirs( 130 self, subprocess, os, root, john): 131 os.path.abspath.return_value = 'current_dir' 132 os.path.join.side_effect = join 133 # If os.path.exists returns True, makedirs is not called 134 os.path.exists.return_value = True 135 136 john['1'].tracking_file = 'faked gpx content' 137 john['1'].tracking_filetype = 'gpx' 138 saved = save_map_screenshot(john['1']) 139 assert saved 140 os.path.abspath.assert_called_once 141 assert os.path.dirname.called 142 assert os.path.join.call_count == 3 143 assert os.path.exists.called 144 assert not os.makedirs.called 145 subprocess.run.assert_called_once 56 146 57 147
Note: See TracChangeset
for help on using the changeset viewer.