mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-08 06:12:51 +00:00
Unit tests: share common code (#31456)
* move set_module_args to units.modules.utils * unit tests: reuse set_module_args * unit tests: mock exit/fail_json in module.utils.ModuleTestCase * unit tests: use module.utils.ModuleTestCase * unit tests: fix 'import shadowed by loop variable'
This commit is contained in:
@@ -1,29 +1,19 @@
|
||||
import json
|
||||
|
||||
from ansible.compat.tests import unittest
|
||||
from ansible.compat.tests.mock import patch
|
||||
from ansible.module_utils import basic
|
||||
from ansible.module_utils.six.moves import xmlrpc_client
|
||||
from ansible.module_utils._text import to_bytes
|
||||
from ansible.modules.packaging.os import rhn_channel
|
||||
|
||||
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
||||
exit_json, fail_json, get_method_name, mock_request)
|
||||
from units.modules.packaging.utils import mock_request
|
||||
from units.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
class TestRhnChannel(unittest.TestCase):
|
||||
class TestRhnChannel(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRhnChannel, self).setUp()
|
||||
|
||||
self.module = rhn_channel
|
||||
self.module.HAS_UP2DATE_CLIENT = True
|
||||
|
||||
self.mock_exit_fail = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
|
||||
self.mock_exit_fail.start()
|
||||
self.addCleanup(self.mock_exit_fail.stop)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_without_required_parameters(self):
|
||||
"""Failure must occurs when all parameters are missing"""
|
||||
with self.assertRaises(AnsibleFailJson):
|
||||
|
||||
@@ -7,8 +7,8 @@ from ansible.module_utils._text import to_native
|
||||
from ansible.module_utils.six.moves import xmlrpc_client
|
||||
from ansible.modules.packaging.os import rhn_register
|
||||
|
||||
from ..utils import (set_module_args, AnsibleExitJson, AnsibleFailJson,
|
||||
exit_json, fail_json, get_method_name, mock_request)
|
||||
from units.modules.packaging.utils import mock_request
|
||||
from units.modules.utils import set_module_args, AnsibleExitJson, AnsibleFailJson, ModuleTestCase
|
||||
|
||||
|
||||
SYSTEMID = """<?xml version="1.0"?>
|
||||
@@ -37,9 +37,11 @@ def skipWhenAllModulesMissing(modules):
|
||||
return unittest.skip("{0}: none are available".format(', '.join(modules)))
|
||||
|
||||
|
||||
class TestRhnRegister(unittest.TestCase):
|
||||
class TestRhnRegister(ModuleTestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestRhnRegister, self).setUp()
|
||||
|
||||
self.module = rhn_register
|
||||
self.module.HAS_UP2DATE_CLIENT = True
|
||||
|
||||
@@ -51,17 +53,10 @@ class TestRhnRegister(unittest.TestCase):
|
||||
self.mock_load_config.start()
|
||||
self.addCleanup(self.mock_load_config.stop)
|
||||
|
||||
self.mock_exit_fail = patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
|
||||
self.mock_exit_fail.start()
|
||||
self.addCleanup(self.mock_exit_fail.stop)
|
||||
|
||||
enable_patcher = patch.object(rhn_register.Rhn, 'enable')
|
||||
self.mock_enable = enable_patcher.start()
|
||||
self.addCleanup(enable_patcher.stop)
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
# This one fails, module needs to be fixed.
|
||||
# @patch('os.path.isfile')
|
||||
# def test_systemid_requirements_missing(self, mock_isfile):
|
||||
|
||||
Reference in New Issue
Block a user