summaryrefslogtreecommitdiff
path: root/test/units/modules/system/test_iptables.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/units/modules/system/test_iptables.py')
-rw-r--r--test/units/modules/system/test_iptables.py43
1 files changed, 6 insertions, 37 deletions
diff --git a/test/units/modules/system/test_iptables.py b/test/units/modules/system/test_iptables.py
index 60e000dc6a..f573a60ff9 100644
--- a/test/units/modules/system/test_iptables.py
+++ b/test/units/modules/system/test_iptables.py
@@ -1,52 +1,21 @@
-import json
-
from ansible.compat.tests import unittest
from ansible.compat.tests.mock import patch
from ansible.module_utils import basic
from ansible.modules.system import iptables
-from ansible.module_utils._text import to_bytes
-
-
-def set_module_args(args):
- args = json.dumps({'ANSIBLE_MODULE_ARGS': args})
- basic._ANSIBLE_ARGS = to_bytes(args)
-
-
-class AnsibleExitJson(Exception):
- pass
-
-
-class AnsibleFailJson(Exception):
- pass
-
-
-def exit_json(*args, **kwargs):
- if 'changed' not in kwargs:
- kwargs['changed'] = False
- raise AnsibleExitJson(kwargs)
-
-
-def fail_json(*args, **kwargs):
- kwargs['failed'] = True
- raise AnsibleFailJson(kwargs)
+from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase, set_module_args
def get_bin_path(*args, **kwargs):
return "/sbin/iptables"
-class TestIptables(unittest.TestCase):
+class TestIptables(ModuleTestCase):
def setUp(self):
- self.mock_basic = patch.multiple(basic.AnsibleModule,
- exit_json=exit_json,
- fail_json=fail_json,
- get_bin_path=get_bin_path)
- self.mock_basic.start()
- self.addCleanup(self.mock_basic.stop)
-
- def tearDown(self):
- pass
+ super(TestIptables, self).setUp()
+ self.mock_get_bin_path = patch.object(basic.AnsibleModule, 'get_bin_path', get_bin_path)
+ self.mock_get_bin_path.start()
+ self.addCleanup(self.mock_get_bin_path.stop) # ensure that the patching is 'undone'
def test_without_required_parameters(self):
"""Failure must occurs when all parameters are missing"""