diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-18 05:52:35 +0000 |
commit | 7fec0b69a082aaeec72fee0612766aa42f6b1b4d (patch) | |
tree | efb569b86ca4da888717f5433e757145fa322e08 /ansible_collections/infoblox/nios_modules/tests/unit | |
parent | Releasing progress-linux version 7.7.0+dfsg-3~progress7.99u1. (diff) | |
download | ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.tar.xz ansible-7fec0b69a082aaeec72fee0612766aa42f6b1b4d.zip |
Merging upstream version 9.4.0+dfsg.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/infoblox/nios_modules/tests/unit')
10 files changed, 967 insertions, 5 deletions
diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/module_utils/test_api.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/module_utils/test_api.py index 9636c05bb..18d02fafa 100644 --- a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/module_utils/test_api.py +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/module_utils/test_api.py @@ -5,8 +5,10 @@ from __future__ import absolute_import, division, print_function __metaclass__ = type import copy - -from ansible_collections.infoblox.nios_modules.tests.unit.compat import unittest +try: + from ansible_collections.infoblox.nios_modules.tests.unit.compat import unittest +except ImportError: + import unittest from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock from ansible_collections.infoblox.nios_modules.plugins.module_utils import api diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py new file mode 100644 index 000000000..d053f0bfe --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_http.py @@ -0,0 +1,136 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_http +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcHttpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_http + + def setUp(self): + super(TestNiosDtcHttpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_http.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcHttpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_http_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'port': 443, 'secure': True, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "secure": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'https_monitor', + 'port': 443, 'secure': True}) + + def test_nios_dtc_monitor_http_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'https_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_http_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'https_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:http/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "https_monitor", + "port": 443, + "secure": True, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py new file mode 100644 index 000000000..fb4b300dd --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_icmp.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_icmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcIcmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_icmp + + def setUp(self): + super(TestNiosDtcIcmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_icmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcIcmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_icmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'icmp_monitor'}) + + def test_nios_dtc_monitor_icmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'icmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_icmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'icmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:icmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "icmp_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py new file mode 100644 index 000000000..802637840 --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_pdp.py @@ -0,0 +1,131 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_pdp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_pdp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_pdp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_pdp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'pdp_monitor'}) + + def test_nios_dtc_monitor_pdp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'pdp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_pdp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'pdp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:pdp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "pdp_monitor", + "port": 2123, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py new file mode 100644 index 000000000..90b86bfa5 --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_sip.py @@ -0,0 +1,129 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_sip +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSipMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_sip + + def setUp(self): + super(TestNiosDtcSipMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_sip.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSipMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_sip_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'sip_monitor'}) + + def test_nios_dtc_monitor_sip_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'sip_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_sip_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'sip_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:sip/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "sip_monitor", + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py new file mode 100644 index 000000000..838a35ebd --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_snmp.py @@ -0,0 +1,143 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_snmp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcSnmpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_snmp + + def setUp(self): + super(TestNiosDtcSnmpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_snmp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcSnmpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_snmp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'snmp_monitor'}) + + def test_nios_dtc_monitor_snmp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'snmp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_snmp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'snmp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:snmp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "snmp_monitor", + "port": 161, + "version": "V2C", + "community": "public", + "interval": 5, + "retry_down": 1, + "retry_up": 1, + "timeout": 15, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py new file mode 100644 index 000000000..072ba1a37 --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_monitor_tcp.py @@ -0,0 +1,133 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_monitor_tcp +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTcpMonitorModule(TestNiosModule): + + module = nios_dtc_monitor_tcp + + def setUp(self): + super(TestNiosDtcTcpMonitorModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_monitor_tcp.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTcpMonitorModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_monitor_tcp_create(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'port': 8080, 'comment': None, 'extattrs': None} + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "port": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with('testobject', {'name': 'tcp_monitor', + 'port': 8080}) + + def test_nios_dtc_monitor_tcp_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'tcp_monitor', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + "comment": "test comment", + "_ref": "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/true", + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_monitor_tcp_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'tcp_monitor', + 'comment': None, 'extattrs': None} + + ref = "dtc:monitor:tcp/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": "test comment", + "_ref": ref, + "name": "tcp_monitor", + "port": 8080, + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_topology.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_topology.py new file mode 100644 index 000000000..d0ee4c69a --- /dev/null +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/test_nios_dtc_topology.py @@ -0,0 +1,156 @@ +# This file is part of Ansible +# +# Ansible is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# Ansible is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Ansible. If not, see <http://www.gnu.org/licenses/>. + + +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + + +from ansible_collections.infoblox.nios_modules.plugins.modules import nios_dtc_topology +from ansible_collections.infoblox.nios_modules.plugins.module_utils import api +from ansible_collections.infoblox.nios_modules.tests.unit.compat.mock import patch, MagicMock, Mock +from .test_nios_module import TestNiosModule, load_fixture + + +class TestNiosDtcTopologyModule(TestNiosModule): + + module = nios_dtc_topology + + def setUp(self): + super(TestNiosDtcTopologyModule, self).setUp() + self.module = MagicMock(name='ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.module.check_mode = False + self.module.params = {'provider': None} + self.mock_wapi = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule') + self.exec_command = self.mock_wapi.start() + self.mock_wapi_run = patch('ansible_collections.infoblox.nios_modules.plugins.modules.nios_dtc_topology.WapiModule.run') + self.mock_wapi_run.start() + self.load_config = self.mock_wapi_run.start() + self.mock_check_type_dict = patch('ansible.module_utils.common.validation.check_type_dict') + self.mock_check_type_dict_obj = self.mock_check_type_dict.start() + + def tearDown(self): + super(TestNiosDtcTopologyModule, self).tearDown() + self.mock_wapi.stop() + self.mock_wapi_run.stop() + self.mock_check_type_dict.stop() + + def _get_wapi(self, test_object): + wapi = api.WapiModule(self.module) + wapi.get_object = Mock(name='get_object', return_value=test_object) + wapi.create_object = Mock(name='create_object') + wapi.update_object = Mock(name='update_object') + wapi.delete_object = Mock(name='delete_object') + return wapi + + def load_fixtures(self, commands=None): + self.exec_command.return_value = (0, load_fixture('nios_result.txt').strip(), None) + self.load_config.return_value = dict(diff=None, session='session') + + def test_nios_dtc_topology_create(self): + self.module.params = { + 'provider': None, + 'state': 'present', + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }], + 'comment': None, + 'extattrs': None + } + + test_object = None + + test_spec = { + "name": {"ib_req": True}, + "rules": {}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.create_object.assert_called_once_with( + 'testobject', + { + 'name': 'a_topology', + 'rules': [{ + 'dest_type': 'POOL', + 'destination_link': 'web_pool', + 'return_type': 'REGULAR' + }] + } + ) + + def test_nios_dtc_topology_update_comment(self): + self.module.params = {'provider': None, 'state': 'present', 'name': 'a_topology', + 'comment': 'updated comment', 'extattrs': None} + + test_object = [ + { + '_ref': 'dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/true', + 'name': 'a_topology', + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + 'comment': "test comment", + 'extattrs': {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + + def test_nios_dtc_topology_remove(self): + self.module.params = {'provider': None, 'state': 'absent', 'name': 'a_topology', + 'comment': None, 'extattrs': None} + + ref = "dtc:topology/ZG5zLm5ldHdvcmtfdmlldyQw:default/false" + + test_object = [ + { + "comment": {}, + "_ref": ref, + "name": "a_topology", + 'rules': [{ + '_ref': 'dtc:topology:rule/ZG5zLm5ldHdvcmtfdmlldyQw:a_topology/web_pool' + }], + "extattrs": {} + } + ] + + test_spec = { + "name": {"ib_req": True}, + "comment": {}, + "extattrs": {} + } + + wapi = self._get_wapi(test_object) + res = wapi.run('testobject', test_spec) + + self.assertTrue(res['changed']) + wapi.delete_object.assert_called_once_with(ref) diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py index 6a00fd25f..15e7ec14d 100644 --- a/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py +++ b/ansible_collections/infoblox/nios_modules/tests/unit/plugins/modules/utils.py @@ -4,8 +4,10 @@ from __future__ import (absolute_import, division, print_function) __metaclass__ = type import json - -from ansible_collections.community.general.tests.unit.compat import unittest +try: + from ansible_collections.community.general.tests.unit.compat import unittest +except ImportError: + import unittest from ansible_collections.community.general.tests.unit.compat.mock import patch from ansible.module_utils import basic from ansible.module_utils.common.text.converters import to_bytes diff --git a/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt b/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt index a0a2eb7ec..fc67ca9e7 100644 --- a/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt +++ b/ansible_collections/infoblox/nios_modules/tests/unit/requirements.txt @@ -5,4 +5,5 @@ pytest-xdist mock pytest-mock pytest-cov -coverage==4.5.4 +coverage==7.3.2 + |