[stable-9] Unit tests: make set_module_args() a context manager, and remove copies of it in some tests (#9840)

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.

(cherry picked from commit a1781d09dd)
This commit is contained in:
Felix Fontein 2025-03-07 07:31:42 +01:00 committed by GitHub
parent 9a6bd80613
commit 013fb9c006
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
80 changed files with 3745 additions and 3977 deletions

View file

@ -56,19 +56,19 @@ class TestDNSimple_Info(ModuleTestCase):
def test_with_no_parameters(self):
"""Failure must occurs when all parameters are missing"""
with self.assertRaises(AnsibleFailJson):
set_module_args({})
self.module.main()
with set_module_args({}):
self.module.main()
@with_httmock(zones_resp)
def test_only_key_and_account(self):
"""key and account will pass, returns domains"""
account_id = "1234"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
with set_module_args({
"api_key": "abcd1324",
"account_id": account_id
})
self.module.main()
}):
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])
@ -80,12 +80,12 @@ class TestDNSimple_Info(ModuleTestCase):
"""name and no record should not fail, returns the record"""
name = "example.com"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
with set_module_args({
"api_key": "abcd1324",
"name": "example.com",
"account_id": "1234"
})
self.module.main()
}):
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])
@ -97,13 +97,13 @@ class TestDNSimple_Info(ModuleTestCase):
"""name and record should not fail, returns the record"""
record = "example"
with self.assertRaises(AnsibleExitJson) as exc_info:
set_module_args({
with set_module_args({
"api_key": "abcd1324",
"account_id": "1234",
"name": "example.com",
"record": "example"
})
self.module.main()
}):
self.module.main()
result = exc_info.exception.args[0]
# nothing should change
self.assertFalse(result['changed'])