From f777ade1939f55431eaba3cb231d2a9a3a1105a8 Mon Sep 17 00:00:00 2001 From: Thorsten Sick Date: Mon, 31 Jan 2022 14:39:27 +0100 Subject: [PATCH] fixing unit tests --- app/calderaapi_4.py | 2 +- tests/test_calderacontrol.py | 19 ++++++------------- 2 files changed, 7 insertions(+), 14 deletions(-) diff --git a/app/calderaapi_4.py b/app/calderaapi_4.py index 99efb93..712d9d2 100644 --- a/app/calderaapi_4.py +++ b/app/calderaapi_4.py @@ -538,7 +538,7 @@ class CalderaAPI(): raise ValueError payload = {"state": state} - return self.__contact_server__(payload, method="patch", rest_path=f"api/v2/operations/{operation_id}") + return self.__contact_server__(payload, method="patch", rest_path=f"api/v2/operations/{operation_id}") def list_agents(self): """ Return all agents """ diff --git a/tests/test_calderacontrol.py b/tests/test_calderacontrol.py index 855a06a..91dd59d 100644 --- a/tests/test_calderacontrol.py +++ b/tests/test_calderacontrol.py @@ -300,20 +300,17 @@ class TestExample(unittest.TestCase): self.cc.add_adversary(name, ability) mock_method.assert_called_once_with(exp_4, method="post", rest_path="api/v2/adversaries") - # execute_operation - def test_execute_operation(self): + # set_operation_state + def test_set_operation_state(self): operation_id = "test_opid" state = "paused" - exp = {"index": "operation", - "op_id": operation_id, - "state": state} with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: self.cc.set_operation_state(operation_id, state) - mock_method.assert_called_once_with(exp) + mock_method.assert_called_once_with({'state': 'paused'}, method='patch', rest_path='api/v2/operations/test_opid') # not supported state - def test_execute_operation_not_supported(self): + def test_set_operation_state_not_supported(self): operation_id = "test_opid" state = "not supported" @@ -321,16 +318,12 @@ class TestExample(unittest.TestCase): with patch.object(self.cc, "__contact_server__", return_value=None): self.cc.set_operation_state(operation_id, state) - def test_execute_operation_default(self): + def test_set_operation_state_default(self): operation_id = "test_opid" - exp = {"index": "operation", - "op_id": operation_id, - "state": "running" # default - } with patch.object(self.cc, "__contact_server__", return_value=None) as mock_method: self.cc.set_operation_state(operation_id) - mock_method.assert_called_once_with(exp) + mock_method.assert_called_once_with({'state': 'running'}, method='patch', rest_path='api/v2/operations/test_opid') # delete_operation def test_delete_operation(self):