Commit 05f828a7 authored by Nicolas Wavrant's avatar Nicolas Wavrant

test / runner: tests getCurrentSoftwareReleaseProfile by introducing mocks

parent ef9455ec
...@@ -45,6 +45,7 @@ setup(name=name, ...@@ -45,6 +45,7 @@ setup(name=name,
'GitPython', #needed for git manipulation into slaprunner 'GitPython', #needed for git manipulation into slaprunner
'passlib', 'passlib',
'netifaces', 'netifaces',
'mock',
Please register or sign in to reply
Please register or sign in to reply
] + additional_install_requires, ] + additional_install_requires,
extras_require = { extras_require = {
'lampconfigure': ["mysqlclient"], #needed for MySQL Database access 'lampconfigure': ["mysqlclient"], #needed for MySQL Database access
......
import mock
import os import os
import string import string
import random import random
...@@ -30,6 +31,38 @@ class TestRunner(unittest.TestCase): ...@@ -30,6 +31,38 @@ class TestRunner(unittest.TestCase):
runner_utils.updateUserCredential(config, login, new_password) runner_utils.updateUserCredential(config, login, new_password)
self.assertTrue(runner_utils.checkUserCredential(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__': if __name__ == '__main__':
random.seed() random.seed()
unittest.main() 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