Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dweinholz committed Dec 11, 2024
1 parent 475bd27 commit bff63ef
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
6 changes: 3 additions & 3 deletions simple_vm_client/forc_connector/template/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 []
Expand All @@ -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,
)

Expand Down
36 changes: 20 additions & 16 deletions simple_vm_client/forc_connector/test_forc_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bff63ef

Please sign in to comment.