mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 20:31:27 -07:00
Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9838)
Make set_module_args() a context manager, and remove copies of set_module_args(). Prepares for Data Tagging.
This commit is contained in:
parent
402f725424
commit
a1781d09dd
84 changed files with 4043 additions and 4302 deletions
|
@ -19,14 +19,14 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
|
||||
def test_missing_keys_with_present_state(self):
|
||||
with self.assertRaises(AnsibleFailJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
'repository': 'repo',
|
||||
'state': 'present',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(exec_info.exception.args[0]['msg'], self.module.error_messages['required_keys'])
|
||||
|
||||
|
@ -34,7 +34,7 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_create_keys(self, *args):
|
||||
with patch.object(self.module, 'update_ssh_key_pair') as update_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'user': 'ABC',
|
||||
'password': 'XXX',
|
||||
'workspace': 'name',
|
||||
|
@ -42,8 +42,8 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
'public_key': 'public',
|
||||
'private_key': 'PRIVATE',
|
||||
'state': 'present',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(update_ssh_key_pair_mock.call_count, 1)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
@ -53,7 +53,7 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_create_keys_check_mode(self, *args):
|
||||
with patch.object(self.module, 'update_ssh_key_pair') as update_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
|
@ -62,8 +62,8 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
'private_key': 'PRIVATE',
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': True,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(update_ssh_key_pair_mock.call_count, 0)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
@ -76,7 +76,7 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_update_keys(self, *args):
|
||||
with patch.object(self.module, 'update_ssh_key_pair') as update_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
|
@ -84,8 +84,8 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
'public_key': 'public',
|
||||
'private_key': 'PRIVATE',
|
||||
'state': 'present',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(update_ssh_key_pair_mock.call_count, 1)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
@ -98,7 +98,7 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_dont_update_same_key(self, *args):
|
||||
with patch.object(self.module, 'update_ssh_key_pair') as update_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
|
@ -106,8 +106,8 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
'public_key': 'public',
|
||||
'private_key': 'PRIVATE',
|
||||
'state': 'present',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(update_ssh_key_pair_mock.call_count, 0)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], False)
|
||||
|
@ -120,7 +120,7 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_update_keys_check_mode(self, *args):
|
||||
with patch.object(self.module, 'update_ssh_key_pair') as update_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
|
@ -129,8 +129,8 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
'private_key': 'PRIVATE',
|
||||
'state': 'present',
|
||||
'_ansible_check_mode': True,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(update_ssh_key_pair_mock.call_count, 0)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
@ -143,14 +143,14 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_delete_keys(self, *args):
|
||||
with patch.object(self.module, 'delete_ssh_key_pair') as delete_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
'repository': 'repo',
|
||||
'state': 'absent',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(delete_ssh_key_pair_mock.call_count, 1)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
@ -160,14 +160,14 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_delete_absent_keys(self, *args):
|
||||
with patch.object(self.module, 'delete_ssh_key_pair') as delete_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
'repository': 'repo',
|
||||
'state': 'absent',
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(delete_ssh_key_pair_mock.call_count, 0)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], False)
|
||||
|
@ -180,15 +180,15 @@ class TestBucketPipelineKeyPairModule(ModuleTestCase):
|
|||
def test_delete_keys_check_mode(self, *args):
|
||||
with patch.object(self.module, 'delete_ssh_key_pair') as delete_ssh_key_pair_mock:
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
set_module_args({
|
||||
with set_module_args({
|
||||
'client_id': 'ABC',
|
||||
'client_secret': 'XXX',
|
||||
'workspace': 'name',
|
||||
'repository': 'repo',
|
||||
'state': 'absent',
|
||||
'_ansible_check_mode': True,
|
||||
})
|
||||
self.module.main()
|
||||
}):
|
||||
self.module.main()
|
||||
|
||||
self.assertEqual(delete_ssh_key_pair_mock.call_count, 0)
|
||||
self.assertEqual(exec_info.exception.args[0]['changed'], True)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue