diff options
Diffstat (limited to 'test/units/modules/network/asa')
-rw-r--r-- | test/units/modules/network/asa/asa_module.py | 76 | ||||
-rw-r--r-- | test/units/modules/network/asa/fixtures/asa_og_config.cfg | 5 | ||||
-rw-r--r-- | test/units/modules/network/asa/test_asa_og.py | 107 |
3 files changed, 0 insertions, 188 deletions
diff --git a/test/units/modules/network/asa/asa_module.py b/test/units/modules/network/asa/asa_module.py deleted file mode 100644 index 681fa1ff16..0000000000 --- a/test/units/modules/network/asa/asa_module.py +++ /dev/null @@ -1,76 +0,0 @@ -# -*- coding: utf-8 -*- - -# (c) 2019, Ansible by Red Hat, inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -import os -import json - -from units.modules.utils import AnsibleExitJson, AnsibleFailJson, ModuleTestCase - - -fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') -fixture_data = {} - - -def load_fixture(name): - path = os.path.join(fixture_path, name) - - if path in fixture_data: - return fixture_data[path] - - with open(path) as f: - data = f.read() - - try: - data = json.loads(data) - except Exception: - pass - - fixture_data[path] = data - return data - - -class TestAsaModule(ModuleTestCase): - - def execute_module(self, failed=False, changed=False, commands=None, sort=True, defaults=False): - - self.load_fixtures(commands) - - if failed: - result = self.failed() - self.assertTrue(result['failed'], result) - else: - result = self.changed(changed) - self.assertEqual(result['changed'], changed, result) - - if commands is not None: - if sort: - self.assertEqual(sorted(commands), sorted(result['commands']), result['commands']) - else: - self.assertEqual(commands, result['commands'], result['commands']) - - return result - - def failed(self): - with self.assertRaises(AnsibleFailJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertTrue(result['failed'], result) - return result - - def changed(self, changed=False): - with self.assertRaises(AnsibleExitJson) as exc: - self.module.main() - - result = exc.exception.args[0] - self.assertEqual(result['changed'], changed, result) - return result - - def load_fixtures(self, commands=None): - pass diff --git a/test/units/modules/network/asa/fixtures/asa_og_config.cfg b/test/units/modules/network/asa/fixtures/asa_og_config.cfg deleted file mode 100644 index 27f2212031..0000000000 --- a/test/units/modules/network/asa/fixtures/asa_og_config.cfg +++ /dev/null @@ -1,5 +0,0 @@ -object-group network test_nets -description ansible_test object-group description -network-object host 8.8.8.8 -network-object 192.168.0.0 255.255.0.0 -group-object awx_lon diff --git a/test/units/modules/network/asa/test_asa_og.py b/test/units/modules/network/asa/test_asa_og.py deleted file mode 100644 index 9b3a569fb8..0000000000 --- a/test/units/modules/network/asa/test_asa_og.py +++ /dev/null @@ -1,107 +0,0 @@ -# -*- coding: utf-8 -*- - -# (c) 2019, Ansible by Red Hat, inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -# Make coding more python3-ish -from __future__ import (absolute_import, division, print_function) -__metaclass__ = type - -from units.compat.mock import patch -from ansible.modules.network.asa import asa_og -from units.modules.utils import set_module_args -from .asa_module import TestAsaModule, load_fixture - - -class TestAsaOgModule(TestAsaModule): - - module = asa_og - - def setUp(self): - super(TestAsaOgModule, self).setUp() - - self.mock_get_config = patch('ansible.modules.network.asa.asa_og.get_config') - self.get_config = self.mock_get_config.start() - - self.mock_load_config = patch('ansible.modules.network.asa.asa_og.load_config') - self.load_config = self.mock_load_config.start() - - self.mock_get_connection = patch('ansible.module_utils.network.asa.asa.get_connection') - self.get_connection = self.mock_get_connection.start() - - def tearDown(self): - super(TestAsaOgModule, self).tearDown() - self.mock_get_config.stop() - self.mock_load_config.stop() - - def load_fixtures(self, commands=None): - self.get_config.return_value = load_fixture('asa_og_config.cfg').strip() - self.load_config.return_value = dict(diff=None, session='session') - - def test_asa_og_idempotent(self): - set_module_args(dict( - name='test_nets', - group_type='network-object', - host_ip=['8.8.8.8'], - ip_mask=['192.168.0.0 255.255.0.0'], - group_object=['awx_lon'], - description='ansible_test object-group description', - state='present' - )) - commands = [] - self.execute_module(changed=False, commands=commands) - - def test_asa_og_add(self): - set_module_args(dict( - name='test_nets', - group_type='network-object', - host_ip=['8.8.8.8', '8.8.4.4'], - ip_mask=['192.168.0.0 255.255.0.0', '10.0.0.0 255.255.255.0'], - group_object=['awx_lon', 'awx_ams'], - description='ansible_test object-group description', - state='present' - )) - commands = [ - 'object-group network test_nets', - 'network-object host 8.8.4.4', - 'network-object 10.0.0.0 255.255.255.0', - 'group-object awx_ams' - ] - self.execute_module(changed=True, commands=commands) - - def test_asa_og_replace(self): - set_module_args(dict( - name='test_nets', - group_type='network-object', - host_ip=['8.8.4.4'], - ip_mask=['10.0.0.0 255.255.255.0'], - group_object=['awx_ams'], - description='ansible_test custom description', - state='replace' - )) - commands = [ - 'object-group network test_nets', - 'description ansible_test custom description', - 'no network-object host 8.8.8.8', - 'network-object host 8.8.4.4', - 'no network-object 192.168.0.0 255.255.0.0', - 'network-object 10.0.0.0 255.255.255.0', - 'no group-object awx_lon', - 'group-object awx_ams' - ] - self.execute_module(changed=True, commands=commands) - - def test_asa_og_remove(self): - set_module_args(dict( - name='test_nets', - group_type='network-object', - host_ip=['8.8.8.8'], - group_object=['awx_lon'], - state='absent' - )) - commands = [ - 'object-group network test_nets', - 'no network-object host 8.8.8.8', - 'no group-object awx_lon' - ] - self.execute_module(changed=True, commands=commands) |