mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-06-03 06:49:10 -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
|
@ -163,17 +163,16 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
]
|
||||
changed = True
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before, copy_auth_flow=return_value_copied,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before, copy_auth_flow=return_value_copied,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -256,17 +255,16 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
]
|
||||
changed = False
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -328,17 +326,16 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
]
|
||||
changed = True
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after, create_empty_auth_flow=return_value_created_empty_flow) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after, create_empty_auth_flow=return_value_created_empty_flow) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -419,17 +416,16 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
]
|
||||
changed = True
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -472,16 +468,15 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
}]
|
||||
changed = True
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -508,16 +503,15 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
return_value_auth_flow_before = [{}]
|
||||
changed = False
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
@ -596,17 +590,16 @@ class TestKeycloakAuthentication(ModuleTestCase):
|
|||
]
|
||||
changed = True
|
||||
|
||||
set_module_args(module_args)
|
||||
|
||||
# Run the module
|
||||
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after, create_empty_auth_flow=return_value_created_empty_flow) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
with set_module_args(module_args):
|
||||
with mock_good_connection():
|
||||
with patch_keycloak_api(get_authentication_flow_by_alias=return_value_auth_flow_before,
|
||||
get_executions_representation=return_value_executions_after, create_empty_auth_flow=return_value_created_empty_flow) \
|
||||
as (mock_get_authentication_flow_by_alias, mock_copy_auth_flow, mock_create_empty_auth_flow,
|
||||
mock_get_executions_representation, mock_delete_authentication_flow_by_id):
|
||||
with self.assertRaises(AnsibleExitJson) as exec_info:
|
||||
self.module.main()
|
||||
|
||||
# Verify number of call on each mock
|
||||
self.assertEqual(len(mock_get_authentication_flow_by_alias.mock_calls), 1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue