From bff63efea61380f77d3c6e1cb7d8216259db9792 Mon Sep 17 00:00:00 2001 From: dweinholz Date: Wed, 11 Dec 2024 10:52:07 +0100 Subject: [PATCH] fixed tests --- .../forc_connector/template/test_templates.py | 6 ++-- .../forc_connector/test_forc_connector.py | 36 ++++++++++--------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/simple_vm_client/forc_connector/template/test_templates.py b/simple_vm_client/forc_connector/template/test_templates.py index eb55c3a..0962cd3 100644 --- a/simple_vm_client/forc_connector/template/test_templates.py +++ b/simple_vm_client/forc_connector/template/test_templates.py @@ -184,7 +184,7 @@ def test_copy_resenvs_templates( mock_glob.return_value = ["/path/to/directory/resenvs"] def mock_glob_side_effect(pattern): - if pattern == Template.get_playbook_dir() + "*": + if pattern == Template.get_playbook_resenvs_dir() + "*": return ["/path/to/directory/resenvs"] else: return [] @@ -195,12 +195,12 @@ def mock_glob_side_effect(pattern): template._copy_resenvs_templates() # Assert that glob.glob was called with the correct parameters - mock_glob.assert_called_once_with(Template.get_playbook_dir() + "*") + mock_glob.assert_called_once_with(Template.get_playbook_resenvs_dir() + "*") # Assert that shutil.copytree was called with the correct parameters mock_copytree.assert_called_once_with( "/path/to/directory/resenvs", - Template.get_playbook_dir(), + Template.get_playbook_resenvs_dir(), dirs_exist_ok=True, ) diff --git a/simple_vm_client/forc_connector/test_forc_connector.py b/simple_vm_client/forc_connector/test_forc_connector.py index 877b861..1eb77fc 100644 --- a/simple_vm_client/forc_connector/test_forc_connector.py +++ b/simple_vm_client/forc_connector/test_forc_connector.py @@ -398,7 +398,7 @@ def test_get_playbook_status(self): fake_server = fakes.generate_fake_resource(Server) fake_server.task_state = None fake_playbook = MagicMock() - self.forc_connector._active_playbooks[fake_server.id] = fake_playbook + ForcConnector.active_playbooks[fake_server.id] = fake_playbook self.forc_connector.redis_connection.exists.return_value = 1 self.forc_connector.redis_connection.hget.return_value = ( VmTaskStates.PREPARE_PLAYBOOK_BUILD.value.encode("utf-8") @@ -428,24 +428,28 @@ def test_create_and_deploy_playbook(self, mock_playbook): playbook_mock = MagicMock() mock_playbook.return_value = playbook_mock - self.forc_connector.redis_connection.hget.return_value = key.encode("utf-8") - res = self.forc_connector.create_and_deploy_playbook( - public_key=key, - research_environment_template="vscode", - create_only_backend=False, - conda_packages=[], - apt_packages=[], - openstack_id=openstack_id, - port=80, - ip="192.168.0.1", - cloud_site="Bielefeld", - base_url="base_url", - ) + with patch.object( + self.forc_connector.template, "is_update_locked", return_value=False + ) as mock_is_update_locked: + + self.forc_connector.redis_connection.hget.return_value = key.encode("utf-8") + res = self.forc_connector.create_and_deploy_playbook( + public_key=key, + research_environment_template="vscode", + create_only_backend=False, + conda_packages=[], + apt_packages=[], + openstack_id=openstack_id, + port=80, + ip="192.168.0.1", + cloud_site="Bielefeld", + base_url="base_url", + ) self.forc_connector.redis_connection.hset.assert_called_once_with( openstack_id, "status", VmTaskStates.BUILD_PLAYBOOK.value ) self.assertEqual(res, 0) - active_play = self.forc_connector._active_playbooks[openstack_id] + active_play = ForcConnector.active_playbooks[openstack_id] self.assertEqual(active_play, playbook_mock) @patch("simple_vm_client.forc_connector.forc_connector.requests.post") @@ -617,7 +621,7 @@ def test_get_playbook_logs(self): self.forc_connector.redis_connection.exists.return_value = 1 playbook_mock = MagicMock() playbook_mock.get_logs.return_value = "status", "stdout", "stderr" - self.forc_connector._active_playbooks = {openstack_id: playbook_mock} + ForcConnector.active_playbooks = {openstack_id: playbook_mock} self.forc_connector.get_playbook_logs(openstack_id=openstack_id) self.forc_connector.redis_connection.exists.assert_called_once_with( openstack_id