Commit ee5a9df0 by Chif Gergő

Add basic tests

parent b5a40679
Pipeline #803 failed with stage
in 39 seconds
......@@ -2,4 +2,5 @@ unittest:
image: python:3.7.3
script:
- pip install -r requirements.txt
- cd ..
- python -m unittest discover
......@@ -33,10 +33,24 @@ fake_auth = {
class InstanceCreateTestCase(unittest.TestCase):
'''
Test openstack methods called with the right values or exceptions raised.
Signature of tests:
def test_my_feature_with(self):
# Mock
--- mocking openstack compute API ---
# Execute
--- execute the tested method ---
# Assert
--- check values, exceptions, calls etc. ---
'''
@patch('openstack.connect')
def setUp(self, mock_connect):
self.compute = MagicMock()
self.compute.get_server = MagicMock(return_value=servers[0])
mock_connect().compute = self.compute
self.manager = OSVirtualMachineManager(auth=fake_auth)
......@@ -77,4 +91,57 @@ class InstanceCreateTestCase(unittest.TestCase):
)
def test_suspend(self):
self.manager.openstack.compute.suspend_server()
# Mock
self.compute.suspend_server = MagicMock(return_value=True)
# Execute
self.manager.suspend_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.suspend_server.assert_called_once()
def test_start(self):
# Mock
self.compute.start_server = MagicMock(return_value=True)
# Execute
self.manager.start_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.start_server.assert_called_once()
def test_stop(self):
# Mock
self.compute.stop_server = MagicMock(return_value=True)
# Execute
self.manager.stop_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.stop_server.assert_called_once()
def test_wake_up(self):
# Mock
self.compute.resume_server = MagicMock(return_value=True)
# Execute
self.manager.wake_up_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.resume_server.assert_called_once()
def test_reboot(self):
# Mock
self.compute.reboot_server = MagicMock(return_value=True)
# Execute
self.manager.reboot_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.reboot_server.assert_called_once()
self.compute.reboot_server.assert_called_with(servers[0], reboot_type="SOFT")
def test_reset(self):
# Mock
self.compute.reboot_server = MagicMock(return_value=True)
# Execute
self.manager.reset_vm("test1")
# Assert
self.compute.get_server.assert_called()
self.compute.reboot_server.assert_called_once()
self.compute.reboot_server.assert_called_with(servers[0], reboot_type="HARD")
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 sign in to comment