Skip to content

Commit

Permalink
moved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
XaverStiensmeier committed Nov 14, 2024
1 parent 3029431 commit a636e6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def test_write_yaml_alias(self, mock_yaml):
@patch("bibigrid.core.utility.ansible_configurator.generate_site_file_yaml")
@patch("bibigrid.core.utility.ansible_configurator.write_yaml")
@patch("bibigrid.core.utility.ansible_configurator.get_cidrs")
def test_configure_ansible_yaml(self, mock_cidrs, mock_yaml, mock_site, mock_hosts, mock_list, mock_common,
def test_configure_ansible_yaml(self, *, mock_cidrs, mock_yaml, mock_site, mock_hosts, mock_list, mock_common,
mock_worker, mock_write):
mock_cidrs.return_value = 421
mock_list.return_value = {2: 422}
Expand Down Expand Up @@ -428,31 +428,6 @@ def test_write_host_and_group_vars(self, mock_write_yaml):
mock_write_yaml.assert_any_call(os.path.join('/mocked/path/host_vars', 'bibigrid-vpngtw-test-cluster-0.yaml'),
expected_vpn_dict, mock_log)

@patch('os.remove')
@patch('os.listdir')
@patch('os.path.isfile')
@patch('bibigrid.core.utility.ansible_configurator.aRP.GROUP_VARS_FOLDER', '/mocked/path/group_vars')
@patch('bibigrid.core.utility.ansible_configurator.aRP.HOST_VARS_FOLDER', '/mocked/path/host_vars')
@patch('logging.getLogger')
def test_delete_old_vars(self, mock_get_logger, mock_isfile, mock_listdir, mock_remove):
mock_log = MagicMock()
mock_get_logger.return_value = mock_log
mock_isfile.return_value = True

mock_listdir.side_effect = [['file1.yaml', 'file2.yaml'], # Files in GROUP_VARS_FOLDER
['file3.yaml', 'file4.yaml'] # Files in HOST_VARS_FOLDER
]

# Call the function under test
ansible_configurator.delete_old_vars(mock_log)

# Assertions for file removal
mock_remove.assert_any_call('/mocked/path/group_vars/file1.yaml')
mock_remove.assert_any_call('/mocked/path/group_vars/file2.yaml')
mock_remove.assert_any_call('/mocked/path/host_vars/file3.yaml')
mock_remove.assert_any_call('/mocked/path/host_vars/file4.yaml')

self.assertEqual(mock_remove.call_count, 4)

def test_key_present_with_key_to(self):
dict_from = {'source_key': 'value1'}
Expand Down
10 changes: 5 additions & 5 deletions tests/test_create.py → tests/unittests/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_prepare_master_args(self):
volume_return = [42]
with patch.object(creator, "prepare_volumes", return_value=volume_return) as prepare_mock:
self.assertEqual((create.MASTER_IDENTIFIER, configuration["masterInstance"], volume_return),
creator.prepare_vpn_or_master_args(configuration, provider))
creator.prepare_vpn_or_master_args(configuration))
prepare_mock.assert_called_with(provider, [])

def test_prepare_vpn_args(self):
Expand All @@ -95,7 +95,7 @@ def test_prepare_vpn_args(self):
volume_return = [42]
with patch.object(creator, "prepare_volumes", return_value=volume_return) as prepare_mock:
self.assertEqual((create.VPN_WORKER_IDENTIFIER, configuration["vpnInstance"], []),
creator.prepare_vpn_or_master_args(configuration, provider))
creator.prepare_vpn_or_master_args(configuration))
prepare_mock.assert_not_called()

def test_prepare_args_keyerror(self):
Expand Down Expand Up @@ -218,7 +218,7 @@ def test_upload_playbooks(self, mock_execute_ssh, mock_ac_ssh, mock_configure_an
@patch.object(create.Create, "upload_data")
@patch.object(create.Create, "log_cluster_start_info")
@patch("bibigrid.core.actions.terminate.terminate")
def test_create_non_debug(self, mock_terminate, mock_info, mock_up, mock_start, mock_conf, mock_key):
def test_create_non_debug(self, *, mock_terminate, mock_info, mock_up, mock_start, mock_conf, mock_key):
provider = MagicMock()
provider.list_servers.return_value = []
configuration = {"floating_ip": 42}
Expand All @@ -233,7 +233,7 @@ def test_create_non_debug(self, mock_terminate, mock_info, mock_up, mock_start,
@patch.object(create.Create, "start_start_server_threads")
@patch.object(create.Create, "log_cluster_start_info")
@patch("bibigrid.core.actions.terminate.terminate")
def test_create_non_debug_upload_raise(self, mock_terminate, mock_info, mock_start, mock_conf, mock_key):
def test_create_non_debug_upload_raise(self, *, mock_terminate, mock_info, mock_start, mock_conf, mock_key):
provider = MagicMock()
provider.list_servers.return_value = []
configuration = {}
Expand All @@ -252,7 +252,7 @@ def test_create_non_debug_upload_raise(self, mock_terminate, mock_info, mock_sta
@patch.object(create.Create, "upload_data")
@patch.object(create.Create, "log_cluster_start_info")
@patch("bibigrid.core.actions.terminate.terminate")
def test_create_debug(self, mock_terminate, mock_info, mock_up, mock_start, mock_conf, mock_key):
def test_create_debug(self, *, mock_terminate, mock_info, mock_up, mock_start, mock_conf, mock_key):
provider = MagicMock()
provider.list_servers.return_value = []
configuration = {"floating_ip": 42}
Expand Down

0 comments on commit a636e6a

Please sign in to comment.