Commit 7434a6c7 authored by Nicolas Wavrant's avatar Nicolas Wavrant

test / runner: tests getCurrentSoftwareReleaseProfile by introducing mocks

parent 4cff6f48
......@@ -56,6 +56,9 @@ setup(name=name,
'networkbench' : ['pycurl'],
'check_web_page_http_cache_hit' : ['pycurl'], # needed for check_web_page_http_cache_hit module
},
tests_require = [
'mock',
],
zip_safe=False, # proxy depends on Flask, which has issues with
# accessing templates
entry_points={
......
import mock
import os
import string
import random
......@@ -35,6 +36,38 @@ class TestRunner(unittest.TestCase):
runner_utils.updateUserCredential(config, login, new_password)
self.assertTrue(runner_utils.checkUserCredential(config, login, new_password))
@mock.patch('slapos.runner.utils.open')
@mock.patch('os.path.exists')
def test_getCurrentSoftwareReleaseProfile(self, mock_path_exists, mock_open):
"""
* Mock a .project file
* Tests that getCurrentSoftwareReleaseProfile returns an absolute path
"""
cwd = os.getcwd()
# If .project file doesn't exist, then getCurrentSoftwareReleaseProfile
# returns an empty string
config = {'etc_dir': os.path.join(cwd, 'etc'),
'workspace': os.path.join(cwd, 'srv', 'runner'),
'software_profile': 'software.cfg'}
profile = runner_utils.getCurrentSoftwareReleaseProfile(config)
self.assertEqual(profile, "")
# If .project points to a SR that doesn't exist, returns empty string
mock_open.return_value.read.return_value = "workspace/fake/path/"
mock_path_exists.return_value = False
profile = runner_utils.getCurrentSoftwareReleaseProfile(config)
self.assertEqual(profile, "")
# If software_profile exists, getCurrentSoftwareReleaseProfile should
# return its absolute path
mock_open.return_value.read.return_value = "workspace/project/software/"
mock_path_exists.return_value = True
profile = runner_utils.getCurrentSoftwareReleaseProfile(config)
self.assertEqual(profile, os.path.join(config['workspace'], 'project',
'software', config['software_profile']))
if __name__ == '__main__':
random.seed()
unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment