summaryrefslogtreecommitdiffstats
path: root/ansible_collections/check_point/mgmt/tests
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:03:42 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-28 16:03:42 +0000
commit66cec45960ce1d9c794e9399de15c138acb18aed (patch)
tree59cd19d69e9d56b7989b080da7c20ef1a3fe2a5a /ansible_collections/check_point/mgmt/tests
parentInitial commit. (diff)
downloadansible-66cec45960ce1d9c794e9399de15c138acb18aed.tar.xz
ansible-66cec45960ce1d9c794e9399de15c138acb18aed.zip
Adding upstream version 7.3.0+dfsg.upstream/7.3.0+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'ansible_collections/check_point/mgmt/tests')
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_access_rule.py107
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_host.py101
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_session.py69
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_task_facts.py101
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer.py110
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role.py119
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule.py124
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_section.py114
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_api_key.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_data_center_object.py73
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_nat_rule.py79
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range.py116
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator.py123
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site.py136
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category.py112
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group.py121
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_assign_global_assignment.py72
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_data_center_object_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_api_key.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_data_center_object.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_nat_rule.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_discard.py70
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain.py112
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object.py113
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group.py113
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment.py117
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment_facts.py80
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group.py117
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host.py113
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_https_section.py114
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_policy.py76
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_software_package.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_mds_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_rule_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_section.py114
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network.py116
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package.py133
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_publish.py70
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_put_file.py76
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_ips_update.py70
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_script.py75
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone.py113
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group.py121
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other.py133
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc.py115
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp.py134
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp.py134
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp.py137
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_session_facts.py80
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_nat_rule.py75
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_session.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_access_section.py72
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_https_section.py72
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_logs.py75
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_nat_section.py72
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_software_package_details.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway.py117
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag.py117
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception.py119
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator.py145
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer.py109
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile.py150
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_protection_override.py79
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule.py124
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time.py184
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_uninstall_software_package.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_policy.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_software_package.py71
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed.py142
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star.py148
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard.py116
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard_facts.py82
-rw-r--r--ansible_collections/check_point/mgmt/tests/units/plugins/httpapi/test_checkpoint.py86
115 files changed, 10972 insertions, 0 deletions
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_access_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_access_rule.py
new file mode 100644
index 00000000..e5f70bdb
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_access_rule.py
@@ -0,0 +1,107 @@
+# Copyright (c) 2018 Red Hat
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleFailJson, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import _checkpoint_access_rule
+
+OBJECT = {'layer': 'foo', 'position': 'bar', 'name': 'baz',
+ 'source': [{'name': 'lol'}], 'destination': [{'name': 'Any'}],
+ 'action': {'name': 'drop'}, 'enabled': True}
+PAYLOAD = {'layer': 'foo', 'position': 'bar', 'name': 'baz'}
+
+
+class TestCheckpointAccessRule(object):
+ module = _checkpoint_access_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_access_rule.Connection')
+ return connection_class_mock.return_value
+
+ @pytest.fixture
+ def get_access_rule_200(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_access_rule.get_access_rule')
+ mock_function.return_value = (200, OBJECT)
+ return mock_function.return_value
+
+ @pytest.fixture
+ def get_access_rule_404(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_access_rule.get_access_rule')
+ mock_function.return_value = (404, 'Object not found')
+ return mock_function.return_value
+
+ def test_create(self, get_access_rule_404, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert 'checkpoint_access_rules' in result
+
+ def test_create_idempotent(self, get_access_rule_200, connection_mock):
+ connection_mock.send_request.return_value = (200, PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, get_access_rule_200, connection_mock):
+ payload_for_update = {'enabled': False}
+ payload_for_update.update(PAYLOAD)
+ connection_mock.send_request.return_value = (200, payload_for_update)
+ result = self._run_module(payload_for_update)
+
+ assert result['changed']
+ assert not result['checkpoint_access_rules']['enabled']
+
+ def test_delete(self, get_access_rule_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ payload_for_delete = {'state': 'absent'}
+ payload_for_delete.update(PAYLOAD)
+ result = self._run_module(payload_for_delete)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, get_access_rule_404, connection_mock):
+ payload = {'name': 'baz', 'state': 'absent'}
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(payload)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
+
+ def _run_module_with_fail_json(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleFailJson) as exc:
+ self.module.main()
+ result = exc.value.args[0]
+ return result
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_host.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_host.py
new file mode 100644
index 00000000..b5720c5d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_host.py
@@ -0,0 +1,101 @@
+# Copyright (c) 2018 Red Hat
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleFailJson, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import _checkpoint_host
+
+OBJECT = {'name': 'foo', 'ipv4-address': '192.168.0.15'}
+CREATE_PAYLOAD = {'name': 'foo', 'ip_address': '192.168.0.15'}
+UPDATE_PAYLOAD = {'name': 'foo', 'ip_address': '192.168.0.16'}
+DELETE_PAYLOAD = {'name': 'foo', 'state': 'absent'}
+
+
+class TestCheckpointHost(object):
+ module = _checkpoint_host
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.Connection')
+ return connection_class_mock.return_value
+
+ @pytest.fixture
+ def get_host_200(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.get_host')
+ mock_function.return_value = (200, OBJECT)
+ return mock_function.return_value
+
+ @pytest.fixture
+ def get_host_404(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.get_host')
+ mock_function.return_value = (404, 'Object not found')
+ return mock_function.return_value
+
+ def test_create(self, get_host_404, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert 'checkpoint_hosts' in result
+
+ def test_create_idempotent(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, get_host_404, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
+
+ def _run_module_with_fail_json(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleFailJson) as exc:
+ self.module.main()
+ result = exc.value.args[0]
+ return result
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_session.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_session.py
new file mode 100644
index 00000000..f0ca8358
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_session.py
@@ -0,0 +1,69 @@
+# Copyright (c) 2018 Red Hat
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleFailJson, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import _checkpoint_session
+
+OBJECT = {'uid': '1234'}
+PAYLOAD = {}
+
+
+class TestCheckpointAccessRule(object):
+ module = _checkpoint_session
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_session.Connection')
+ return connection_class_mock.return_value
+
+ @pytest.fixture
+ def get_session_200(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_session.get_session')
+ mock_function.return_value = (200, OBJECT)
+ return mock_function.return_value
+
+ def test_publish(self, get_session_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert 'checkpoint_session' in result
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
+
+ def _run_module_with_fail_json(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleFailJson) as exc:
+ self.module.main()
+ result = exc.value.args[0]
+ return result
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_task_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_task_facts.py
new file mode 100644
index 00000000..b5720c5d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_checkpoint_task_facts.py
@@ -0,0 +1,101 @@
+# Copyright (c) 2018 Red Hat
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleFailJson, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import _checkpoint_host
+
+OBJECT = {'name': 'foo', 'ipv4-address': '192.168.0.15'}
+CREATE_PAYLOAD = {'name': 'foo', 'ip_address': '192.168.0.15'}
+UPDATE_PAYLOAD = {'name': 'foo', 'ip_address': '192.168.0.16'}
+DELETE_PAYLOAD = {'name': 'foo', 'state': 'absent'}
+
+
+class TestCheckpointHost(object):
+ module = _checkpoint_host
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.Connection')
+ return connection_class_mock.return_value
+
+ @pytest.fixture
+ def get_host_200(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.get_host')
+ mock_function.return_value = (200, OBJECT)
+ return mock_function.return_value
+
+ @pytest.fixture
+ def get_host_404(self, mocker):
+ mock_function = mocker.patch('ansible_collections.check_point.mgmt.plugins.modules._checkpoint_host.get_host')
+ mock_function.return_value = (404, 'Object not found')
+ return mock_function.return_value
+
+ def test_create(self, get_host_404, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert 'checkpoint_hosts' in result
+
+ def test_create_idempotent(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete(self, get_host_200, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, get_host_404, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
+
+ def _run_module_with_fail_json(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleFailJson) as exc:
+ self.module.main()
+ result = exc.value.args[0]
+ return result
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer.py
new file mode 100644
index 00000000..7dc292f7
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer.py
@@ -0,0 +1,110 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_layer
+
+OBJECT = {
+ "name": "New Layer 1"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Layer 1"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Layer 1",
+ "applications_and_url_filtering": False
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Layer 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_access_layer.api_call'
+api_call_object = 'access-layer'
+
+
+class TestCheckpointAccessLayer(object):
+ module = cp_mgmt_access_layer
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer_facts.py
new file mode 100644
index 00000000..e7a4d5f1
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_layer_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_layer_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'access-layer'
+api_call_object_plural_version = 'access-layers'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointAccessLayerFacts(object):
+ module = cp_mgmt_access_layer_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role.py
new file mode 100644
index 00000000..ad5194b1
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role.py
@@ -0,0 +1,119 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_role
+
+OBJECT = {
+ "name": "New Access Role 1",
+ "networks": "any",
+ "users": "any",
+ "machines": "all identified",
+ "remote_access_clients": "any"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Access Role 1",
+ "networks": "any",
+ "users": "any",
+ "machines": "all identified",
+ "remote_access_clients": "any"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Access Role 1",
+ "users": "all identified",
+ "machines": "any"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Access Role 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_access_role.api_call'
+api_call_object = 'access-role'
+
+
+class TestCheckpointAccessRole(object):
+ module = cp_mgmt_access_role
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role_facts.py
new file mode 100644
index 00000000..55416777
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_role_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_role_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'access-role'
+api_call_object_plural_version = 'access-roles'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointAccessRoleFacts(object):
+ module = cp_mgmt_access_role_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule.py
new file mode 100644
index 00000000..b0163d70
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule.py
@@ -0,0 +1,124 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_rule
+
+OBJECT = {
+ "layer": "Network",
+ "name": "Rule 1",
+ "service": [
+ "SMTP",
+ "AOL"
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "layer": "Network",
+ "name": "Rule 1",
+ "service": [
+ "SMTP",
+ "AOL"
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Rule 1",
+ "layer": "Network",
+ "action_settings": {
+ "limit": "Upload_1Gbps",
+ "enable_identity_captive_portal": True
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Rule 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_access_rule.api_call'
+api_call_object = 'access-rule'
+
+
+class TestCheckpointAccessRule(object):
+ module = cp_mgmt_access_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule_facts.py
new file mode 100644
index 00000000..87f532c4
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_rule_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_rule_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'access-rule'
+api_call_object_plural_version = 'access-rulebase'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointAccessRuleFacts(object):
+ module = cp_mgmt_access_rule_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_section.py
new file mode 100644
index 00000000..1adc7d5e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_access_section.py
@@ -0,0 +1,114 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_access_section
+
+OBJECT = {
+ "layer": "Network",
+ "position": 1,
+ "name": "New Section 1"
+}
+
+CREATE_PAYLOAD = {
+ "layer": "Network",
+ "position": 1,
+ "name": "New Section 1"
+}
+
+UPDATE_PAYLOAD = {
+ "layer": "Network",
+ "name": "New Section 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Section 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_access_section.api_call'
+api_call_object = 'access-section'
+
+
+class TestCheckpointAccessSection(object):
+ module = cp_mgmt_access_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_api_key.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_api_key.py
new file mode 100644
index 00000000..a3977c56
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_api_key.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_add_api_key
+
+PAYLOAD = {
+ "admin_name": "admin",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'add-api-key'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointAddApiKey(object):
+ module = cp_mgmt_add_api_key
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_data_center_object.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_data_center_object.py
new file mode 100644
index 00000000..63e65675
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_data_center_object.py
@@ -0,0 +1,73 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_add_data_center_object
+
+PAYLOAD = {
+ "uri": "/Datacenters/VMs/My VM1",
+ "name": "VM1 mgmt name",
+ "data_center_name": "vCenter 1",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'add-data-center-object'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointAddDataCenterObject(object):
+ module = cp_mgmt_add_data_center_object
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_nat_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_nat_rule.py
new file mode 100644
index 00000000..dc5dbbf8
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_add_nat_rule.py
@@ -0,0 +1,79 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_add_nat_rule
+
+PAYLOAD = {
+ "package": "standard",
+ "position": 1,
+ "comments": "comment example1 nat999",
+ "enabled": False,
+ "install_on": [
+ "Policy Targets"
+ ],
+ "original_source": "Any",
+ "original_destination": "All_Internet",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'add-nat-rule'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointAddNatRule(object):
+ module = cp_mgmt_add_nat_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range.py
new file mode 100644
index 00000000..42f494e0
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range.py
@@ -0,0 +1,116 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_address_range
+
+OBJECT = {
+ "name": "New Address Range 1",
+ "ip_address_first": "192.0.2.1",
+ "ip_address_last": "192.0.2.10"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Address Range 1",
+ "ip_address_first": "192.0.2.1",
+ "ip_address_last": "192.0.2.10"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Address Range 1",
+ "color": "blue",
+ "ip_address_first": "192.0.2.1",
+ "ip_address_last": "192.0.2.1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Address Range 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_address_range.api_call'
+api_call_object = 'address-range'
+
+
+class TestCheckpointAddressRange(object):
+ module = cp_mgmt_address_range
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range_facts.py
new file mode 100644
index 00000000..9f8da537
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_address_range_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_address_range_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'address-range'
+api_call_object_plural_version = 'address-ranges'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointAddressRangeFacts(object):
+ module = cp_mgmt_address_range_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator.py
new file mode 100644
index 00000000..1c1b2714
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator.py
@@ -0,0 +1,123 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_administrator
+
+OBJECT = {
+ "name": "admin",
+ "password": "secret",
+ "email": "admin@gmail.com",
+ "must_change_password": False,
+ "phone_number": "1800-800-800",
+ "authentication_method": "undefined",
+ "permissions_profile": "read write all"
+}
+
+CREATE_PAYLOAD = {
+ "name": "admin",
+ "password": "secret",
+ "email": "admin@gmail.com",
+ "must_change_password": False,
+ "phone_number": "1800-800-800",
+ "authentication_method": "undefined",
+ "permissions_profile": "read write all"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "admin",
+ "password": "bew secret",
+ "permissions_profile": "read only profile"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "admin",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_administrator.api_call'
+api_call_object = 'administrator'
+
+
+class TestCheckpointAdministrator(object):
+ module = cp_mgmt_administrator
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator_facts.py
new file mode 100644
index 00000000..157e2373
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_administrator_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_administrator_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'administrator'
+api_call_object_plural_version = 'administrators'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointAdministratorFacts(object):
+ module = cp_mgmt_administrator_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site.py
new file mode 100644
index 00000000..7ddf93a2
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site.py
@@ -0,0 +1,136 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site
+
+OBJECT = {
+ "name": "New Application Site 1",
+ "description": "My Application Site",
+ "primary_category": "Social Networking",
+ "additional_categories": [
+ "Instant Chat",
+ "Supports Streaming",
+ "New Application Site Category 1"
+ ],
+ "url_list": [
+ "www.cnet.com",
+ "www.stackoverflow.com"
+ ],
+ "urls_defined_as_regular_expression": False
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Application Site 1",
+ "description": "My Application Site",
+ "primary_category": "Social Networking",
+ "additional_categories": [
+ "Instant Chat",
+ "Supports Streaming",
+ "New Application Site Category 1"
+ ],
+ "url_list": [
+ "www.cnet.com",
+ "www.stackoverflow.com"
+ ],
+ "urls_defined_as_regular_expression": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Application Site 1",
+ "description": "My New Application Site",
+ "primary_category": "Instant Chat",
+ "urls_defined_as_regular_expression": True
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Application Site 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_application_site.api_call'
+api_call_object = 'application-site'
+
+
+class TestCheckpointApplicationSite(object):
+ module = cp_mgmt_application_site
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category.py
new file mode 100644
index 00000000..787e2107
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category.py
@@ -0,0 +1,112 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site_category
+
+OBJECT = {
+ "name": "New Application Site Category 1",
+ "description": "My Application Site category"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Application Site Category 1",
+ "description": "My Application Site category"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Application Site Category 1",
+ "description": "My new Application Site category"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Application Site Category 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_application_site_category.api_call'
+api_call_object = 'application-site-category'
+
+
+class TestCheckpointApplicationSiteCategory(object):
+ module = cp_mgmt_application_site_category
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category_facts.py
new file mode 100644
index 00000000..a46f05fe
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_category_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site_category_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'application-site-category'
+api_call_object_plural_version = 'application-site-categories'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointApplicationSiteCategoryFacts(object):
+ module = cp_mgmt_application_site_category_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_facts.py
new file mode 100644
index 00000000..05f9fcfa
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'application-site'
+api_call_object_plural_version = 'application-sites'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointApplicationSiteFacts(object):
+ module = cp_mgmt_application_site_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group.py
new file mode 100644
index 00000000..25c71bb0
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group.py
@@ -0,0 +1,121 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site_group
+
+OBJECT = {
+ "name": "New Application Site Group 1",
+ "members": [
+ "facebook",
+ "Social Networking",
+ "New Application Site 1",
+ "New Application Site Category 1"
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Application Site Group 1",
+ "members": [
+ "facebook",
+ "Social Networking",
+ "New Application Site 1",
+ "New Application Site Category 1"
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Application Site Group 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Application Site Group 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_application_site_group.api_call'
+api_call_object = 'application-site-group'
+
+
+class TestCheckpointApplicationSiteGroup(object):
+ module = cp_mgmt_application_site_group
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group_facts.py
new file mode 100644
index 00000000..acc88017
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_application_site_group_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_application_site_group_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'application-site-group'
+api_call_object_plural_version = 'application-site-groups'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointApplicationSiteGroupFacts(object):
+ module = cp_mgmt_application_site_group_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_assign_global_assignment.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_assign_global_assignment.py
new file mode 100644
index 00000000..59b9245e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_assign_global_assignment.py
@@ -0,0 +1,72 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_assign_global_assignment
+
+PAYLOAD = {
+ "global_domains": "Global2",
+ "dependent_domains": "domain1",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'assign-global-assignment'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointAssignGlobalAssignment(object):
+ module = cp_mgmt_assign_global_assignment
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_data_center_object_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_data_center_object_facts.py
new file mode 100644
index 00000000..4a5ac2ec
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_data_center_object_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_data_center_object_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'data-center-object'
+api_call_object_plural_version = 'data-center-objects'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointDataCenterObjectFacts(object):
+ module = cp_mgmt_data_center_object_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_api_key.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_api_key.py
new file mode 100644
index 00000000..3fe6f254
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_api_key.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_delete_api_key
+
+PAYLOAD = {
+ "api_key": "eea3be76f4a8eb740ee872bcedc692748ff256a2d21c9ffd2754facbde046d00",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'delete-api-key'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointDeleteApiKey(object):
+ module = cp_mgmt_delete_api_key
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_data_center_object.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_data_center_object.py
new file mode 100644
index 00000000..19230772
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_data_center_object.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_delete_data_center_object
+
+PAYLOAD = {
+ "name": "VM1 mgmt name",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'delete-data-center-object'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointDeleteDataCenterObject(object):
+ module = cp_mgmt_delete_data_center_object
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_nat_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_nat_rule.py
new file mode 100644
index 00000000..9fbfae56
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_delete_nat_rule.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_delete_nat_rule
+
+PAYLOAD = {
+ "package": "standard",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'delete-nat-rule'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointDeleteNatRule(object):
+ module = cp_mgmt_delete_nat_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_discard.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_discard.py
new file mode 100644
index 00000000..052b482e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_discard.py
@@ -0,0 +1,70 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_discard
+
+PAYLOAD = {
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'discard'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointDiscard(object):
+ module = cp_mgmt_discard
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain.py
new file mode 100644
index 00000000..09b03155
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain.py
@@ -0,0 +1,112 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_dns_domain
+
+OBJECT = {
+ "name": ".www.example.com",
+ "is_sub_domain": False
+}
+
+CREATE_PAYLOAD = {
+ "name": ".www.example.com",
+ "is_sub_domain": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": ".www.example.com",
+ "is_sub_domain": True
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": ".www.example.com",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_dns_domain.api_call'
+api_call_object = 'dns-domain'
+
+
+class TestCheckpointDnsDomain(object):
+ module = cp_mgmt_dns_domain
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain_facts.py
new file mode 100644
index 00000000..3cfbe62b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dns_domain_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_dns_domain_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'dns-domain'
+api_call_object_plural_version = 'dns-domains'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointDnsDomainFacts(object):
+ module = cp_mgmt_dns_domain_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object.py
new file mode 100644
index 00000000..f168d60d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object.py
@@ -0,0 +1,113 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_dynamic_object
+
+OBJECT = {
+ "name": "Dynamic_Object_1",
+ "comments": "My Dynamic Object 1",
+ "color": "yellow"
+}
+
+CREATE_PAYLOAD = {
+ "name": "Dynamic_Object_1",
+ "comments": "My Dynamic Object 1",
+ "color": "yellow"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Dynamic_Object_1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Dynamic_Object_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_dynamic_object.api_call'
+api_call_object = 'dynamic-object'
+
+
+class TestCheckpointDynamicObject(object):
+ module = cp_mgmt_dynamic_object
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object_facts.py
new file mode 100644
index 00000000..add11efd
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_dynamic_object_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_dynamic_object_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'dynamic-object'
+api_call_object_plural_version = 'dynamic-objects'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointDynamicObjectFacts(object):
+ module = cp_mgmt_dynamic_object_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group.py
new file mode 100644
index 00000000..7fa127fd
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group.py
@@ -0,0 +1,113 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_exception_group
+
+OBJECT = {
+ "name": "exception_group_2",
+ "apply_on": "manually-select-threat-rules"
+}
+
+CREATE_PAYLOAD = {
+ "name": "exception_group_2",
+ "apply_on": "manually-select-threat-rules"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "exception_group_2",
+ "tags": "tag3",
+ "apply_on": "all-threat-rules"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "exception_group_2",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_exception_group.api_call'
+api_call_object = 'exception-group'
+
+
+class TestCheckpointExceptionGroup(object):
+ module = cp_mgmt_exception_group
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group_facts.py
new file mode 100644
index 00000000..dc3a56ba
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_exception_group_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_exception_group_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'exception-group'
+api_call_object_plural_version = 'exception-groups'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointExceptionGroupFacts(object):
+ module = cp_mgmt_exception_group_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment.py
new file mode 100644
index 00000000..633059c8
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment.py
@@ -0,0 +1,117 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_global_assignment
+
+OBJECT = {
+ "global_domain": "Global",
+ "dependent_domain": "domain2",
+ "global_access_policy": "standard",
+ "global_threat_prevention_policy": "standard",
+ "manage_protection_actions": True
+}
+
+CREATE_PAYLOAD = {
+ "global_domain": "Global",
+ "dependent_domain": "domain2",
+ "global_access_policy": "standard",
+ "global_threat_prevention_policy": "standard",
+ "manage_protection_actions": True
+}
+
+UPDATE_PAYLOAD = {
+ "global_domain": "Global2",
+ "dependent_domain": "domain1",
+ "global_threat_prevention_policy": "",
+ "manage_protection_actions": False
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_global_assignment.api_call'
+api_call_object = 'global-assignment'
+
+
+class TestCheckpointGlobalAssignment(object):
+ module = cp_mgmt_global_assignment
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment_facts.py
new file mode 100644
index 00000000..a997ab8d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_global_assignment_facts.py
@@ -0,0 +1,80 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_global_assignment_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {}
+
+api_call_object = 'global-assignment'
+api_call_object_plural_version = 'global-assignments'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointGlobalAssignmentFacts(object):
+ module = cp_mgmt_global_assignment_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group.py
new file mode 100644
index 00000000..07af4db9
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group.py
@@ -0,0 +1,117 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_group
+
+OBJECT = {
+ "name": "New Group 5",
+ "members": [
+ "New Host 1",
+ "My Test Host 3"
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Group 5",
+ "members": [
+ "New Host 1",
+ "My Test Host 3"
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Group 5"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Group 5",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_group.api_call'
+api_call_object = 'group'
+
+
+class TestCheckpointGroup(object):
+ module = cp_mgmt_group
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_facts.py
new file mode 100644
index 00000000..e85b6b74
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_group_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'group'
+api_call_object_plural_version = 'groups'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointGroupFacts(object):
+ module = cp_mgmt_group_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion.py
new file mode 100644
index 00000000..188fd75b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_group_with_exclusion
+
+OBJECT = {
+ "name": "Group with exclusion",
+ "include": "New Group 1",
+ "except": "New Group 2"
+}
+
+CREATE_PAYLOAD = {
+ "name": "Group with exclusion",
+ "include": "New Group 1",
+ "except": "New Group 2"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Group with exclusion",
+ "include": "New Group 2",
+ "except": "New Group 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Group with exclusion",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_group_with_exclusion.api_call'
+api_call_object = 'group-with-exclusion'
+
+
+class TestCheckpointGroupWithExclusion(object):
+ module = cp_mgmt_group_with_exclusion
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion_facts.py
new file mode 100644
index 00000000..e819625f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_group_with_exclusion_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_group_with_exclusion_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'group-with-exclusion'
+api_call_object_plural_version = 'groups-with-exclusion'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointGroupWithExclusionFacts(object):
+ module = cp_mgmt_group_with_exclusion_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host.py
new file mode 100644
index 00000000..abaa9e3b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host.py
@@ -0,0 +1,113 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_host
+
+OBJECT = {
+ "name": "New Host 1",
+ "ip_address": "192.0.2.1"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Host 1",
+ "ip_address": "192.0.2.1"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Host 1",
+ "color": "blue",
+ "ipv4_address": "192.0.2.2"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Host 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_host.api_call'
+api_call_object = 'host'
+
+
+class TestCheckpointHost(object):
+ module = cp_mgmt_host
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host_facts.py
new file mode 100644
index 00000000..182aa81e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_host_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_host_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'host'
+api_call_object_plural_version = 'hosts'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointHostFacts(object):
+ module = cp_mgmt_host_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_https_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_https_section.py
new file mode 100644
index 00000000..3dc063a3
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_https_section.py
@@ -0,0 +1,114 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_https_section
+
+OBJECT = {
+ "layer": "Default Layer",
+ "position": 1,
+ "name": "New Section 1"
+}
+
+CREATE_PAYLOAD = {
+ "layer": "Default Layer",
+ "position": 1,
+ "name": "New Section 1"
+}
+
+UPDATE_PAYLOAD = {
+ "layer": "Default Layer",
+ "name": "New Section 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Section 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_https_section.api_call'
+api_call_object = 'https-section'
+
+
+class TestCheckpointHttpsSection(object):
+ module = cp_mgmt_https_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_policy.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_policy.py
new file mode 100644
index 00000000..3086f5c9
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_policy.py
@@ -0,0 +1,76 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_install_policy
+
+PAYLOAD = {
+ "access": True,
+ "targets": [
+ "corporate-gateway"
+ ],
+ "policy_package": "standard",
+ "threat_prevention": True,
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'install-policy'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointInstallPolicy(object):
+ module = cp_mgmt_install_policy
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_software_package.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_software_package.py
new file mode 100644
index 00000000..4442abbc
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_install_software_package.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_install_software_package
+
+PAYLOAD = {
+ "name": "Check_Point_R80_40_JHF_MCD_DEMO_019_MAIN_Bundle_T1_VISIBLE_FULL.tgz",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'install-software-package'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointInstallSoftwarePackage(object):
+ module = cp_mgmt_install_software_package
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_mds_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_mds_facts.py
new file mode 100644
index 00000000..938e4a49
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_mds_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_mds_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'mds'
+api_call_object_plural_version = 'mdss'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointMdsFacts(object):
+ module = cp_mgmt_mds_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range.py
new file mode 100644
index 00000000..8a68f901
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_multicast_address_range
+
+OBJECT = {
+ "name": "New Multicast Address Range",
+ "ip_address_first": "224.0.0.1",
+ "ip_address_last": "224.0.0.4"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Multicast Address Range",
+ "ip_address_first": "224.0.0.1",
+ "ip_address_last": "224.0.0.4"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Multicast Address Range",
+ "ip_address_first": "224.0.0.7",
+ "ip_address_last": "224.0.0.10"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Multicast Address Range",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_multicast_address_range.api_call'
+api_call_object = 'multicast-address-range'
+
+
+class TestCheckpointMulticastAddressRange(object):
+ module = cp_mgmt_multicast_address_range
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range_facts.py
new file mode 100644
index 00000000..3de8fa06
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_multicast_address_range_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_multicast_address_range_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'multicast-address-range'
+api_call_object_plural_version = 'multicast-address-ranges'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointMulticastAddressRangeFacts(object):
+ module = cp_mgmt_multicast_address_range_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_rule_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_rule_facts.py
new file mode 100644
index 00000000..eae9cf61
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_rule_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_nat_rule_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'nat-rule'
+api_call_object_plural_version = 'nat-rulebase'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointNatRuleFacts(object):
+ module = cp_mgmt_nat_rule_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_section.py
new file mode 100644
index 00000000..d666ca88
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_nat_section.py
@@ -0,0 +1,114 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_nat_section
+
+OBJECT = {
+ "package": "standard",
+ "name": "New Section 1",
+ "position": 1
+}
+
+CREATE_PAYLOAD = {
+ "package": "standard",
+ "name": "New Section 1",
+ "position": 1
+}
+
+UPDATE_PAYLOAD = {
+ "package": "standard",
+ "name": "New Section 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Section 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_nat_section.api_call'
+api_call_object = 'nat-section'
+
+
+class TestCheckpointNatSection(object):
+ module = cp_mgmt_nat_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network.py
new file mode 100644
index 00000000..0935108f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network.py
@@ -0,0 +1,116 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_network
+
+OBJECT = {
+ "name": "New Network 1",
+ "subnet": "192.0.2.0",
+ "subnet_mask": "255.255.255.0"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Network 1",
+ "subnet": "192.0.2.0",
+ "subnet_mask": "255.255.255.0"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Network 1",
+ "color": "blue",
+ "subnet": "192.0.0.0",
+ "mask_length": 16
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Network 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_network.api_call'
+api_call_object = 'network'
+
+
+class TestCheckpointNetwork(object):
+ module = cp_mgmt_network
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network_facts.py
new file mode 100644
index 00000000..1302dbba
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_network_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_network_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'network'
+api_call_object_plural_version = 'networks'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointNetworkFacts(object):
+ module = cp_mgmt_network_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package.py
new file mode 100644
index 00000000..dd389dad
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package.py
@@ -0,0 +1,133 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_package
+
+OBJECT = {
+ "name": "New_Standard_Package_1",
+ "comments": "My Comments",
+ "color": "orange",
+ "access": True,
+ "threat_prevention": False
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_Standard_Package_1",
+ "comments": "My Comments",
+ "color": "orange",
+ "access": True,
+ "threat_prevention": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_Standard_Package_1",
+ "access_layers": {
+ "add": [
+ {
+ "name": "New Access Layer 1",
+ "position": 1
+ }
+ ]
+ },
+ "threat_layers": {
+ "add": [
+ {
+ "name": "New Layer 1",
+ "position": 2
+ }
+ ]
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_Standard_Package_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_package.api_call'
+api_call_object = 'package'
+
+
+class TestCheckpointPackage(object):
+ module = cp_mgmt_package
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package_facts.py
new file mode 100644
index 00000000..fbb825b3
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_package_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_package_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'package'
+api_call_object_plural_version = 'packages'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointPackageFacts(object):
+ module = cp_mgmt_package_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_publish.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_publish.py
new file mode 100644
index 00000000..bcce0851
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_publish.py
@@ -0,0 +1,70 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_publish
+
+PAYLOAD = {
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'publish'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointPublish(object):
+ module = cp_mgmt_publish
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_put_file.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_put_file.py
new file mode 100644
index 00000000..7ad11efa
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_put_file.py
@@ -0,0 +1,76 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_put_file
+
+PAYLOAD = {
+ "targets": [
+ "corporate-gateway"
+ ],
+ "file_path": "/home/admin/",
+ "file_name": "vsx_conf",
+ "file_content": "vs ip 192.0.2.1\nvs2 ip 192.0.2.2",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'put-file'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointPutFile(object):
+ module = cp_mgmt_put_file
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_ips_update.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_ips_update.py
new file mode 100644
index 00000000..7202790a
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_ips_update.py
@@ -0,0 +1,70 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_run_ips_update
+
+PAYLOAD = {
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'run-ips-update'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointRunIpsUpdate(object):
+ module = cp_mgmt_run_ips_update
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_script.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_script.py
new file mode 100644
index 00000000..730b5bff
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_run_script.py
@@ -0,0 +1,75 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_run_script
+
+PAYLOAD = {
+ "script": "ls -l /",
+ "targets": [
+ "corporate-gateway"
+ ],
+ "script_name": "Script Example: List files under / dir",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'run-script'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointRunScript(object):
+ module = cp_mgmt_run_script
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone.py
new file mode 100644
index 00000000..13ef758b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone.py
@@ -0,0 +1,113 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_security_zone
+
+OBJECT = {
+ "name": "SZone1",
+ "comments": "My Security Zone 1",
+ "color": "yellow"
+}
+
+CREATE_PAYLOAD = {
+ "name": "SZone1",
+ "comments": "My Security Zone 1",
+ "color": "yellow"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "SZone1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "SZone1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_security_zone.api_call'
+api_call_object = 'security-zone'
+
+
+class TestCheckpointSecurityZone(object):
+ module = cp_mgmt_security_zone
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone_facts.py
new file mode 100644
index 00000000..3fa95f4d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_security_zone_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_security_zone_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'security-zone'
+api_call_object_plural_version = 'security-zones'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointSecurityZoneFacts(object):
+ module = cp_mgmt_security_zone_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc.py
new file mode 100644
index 00000000..d8fd216a
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_dce_rpc
+
+OBJECT = {
+ "name": "New_DCE-RPC_Service_1",
+ "interface_uuid": "97aeb460-9aea-11d5-bd16-0090272ccb30",
+ "keep_connections_open_after_policy_installation": False
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_DCE-RPC_Service_1",
+ "interface_uuid": "97aeb460-9aea-11d5-bd16-0090272ccb30",
+ "keep_connections_open_after_policy_installation": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_DCE-RPC_Service_1",
+ "color": "blue",
+ "interface_uuid": "44aeb460-9aea-11d5-bd16-009027266b30"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_DCE-RPC_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_dce_rpc.api_call'
+api_call_object = 'service-dce-rpc'
+
+
+class TestCheckpointServiceDceRpc(object):
+ module = cp_mgmt_service_dce_rpc
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc_facts.py
new file mode 100644
index 00000000..f06c615a
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_dce_rpc_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_dce_rpc_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-dce-rpc'
+api_call_object_plural_version = 'services-dce-rpc'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceDceRpcFacts(object):
+ module = cp_mgmt_service_dce_rpc_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group.py
new file mode 100644
index 00000000..f325f873
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group.py
@@ -0,0 +1,121 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_group
+
+OBJECT = {
+ "name": "New Service Group 1",
+ "members": [
+ "https",
+ "bootp",
+ "nisplus",
+ "HP-OpCdistm"
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Service Group 1",
+ "members": [
+ "https",
+ "bootp",
+ "nisplus",
+ "HP-OpCdistm"
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Service Group 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Service Group 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_group.api_call'
+api_call_object = 'service-group'
+
+
+class TestCheckpointServiceGroup(object):
+ module = cp_mgmt_service_group
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group_facts.py
new file mode 100644
index 00000000..2457157c
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_group_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_group_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-group'
+api_call_object_plural_version = 'service-groups'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceGroupFacts(object):
+ module = cp_mgmt_service_group_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp.py
new file mode 100644
index 00000000..173dfec1
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_icmp
+
+OBJECT = {
+ "name": "Icmp1",
+ "icmp_type": 5,
+ "icmp_code": 7
+}
+
+CREATE_PAYLOAD = {
+ "name": "Icmp1",
+ "icmp_type": 5,
+ "icmp_code": 7
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Icmp1",
+ "icmp_type": 45,
+ "icmp_code": 13
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Icmp1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_icmp.api_call'
+api_call_object = 'service-icmp'
+
+
+class TestCheckpointServiceIcmp(object):
+ module = cp_mgmt_service_icmp
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6.py
new file mode 100644
index 00000000..2194bed2
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_icmp6
+
+OBJECT = {
+ "name": "Icmp1",
+ "icmp_type": 5,
+ "icmp_code": 7
+}
+
+CREATE_PAYLOAD = {
+ "name": "Icmp1",
+ "icmp_type": 5,
+ "icmp_code": 7
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Icmp1",
+ "icmp_type": 45,
+ "icmp_code": 13
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Icmp1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_icmp6.api_call'
+api_call_object = 'service-icmp6'
+
+
+class TestCheckpointServiceIcmp6(object):
+ module = cp_mgmt_service_icmp6
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6_facts.py
new file mode 100644
index 00000000..7ac4fd7a
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp6_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_icmp6_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-icmp6'
+api_call_object_plural_version = 'services-icmp6'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceIcmp6Facts(object):
+ module = cp_mgmt_service_icmp6_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp_facts.py
new file mode 100644
index 00000000..c5979e7f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_icmp_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_icmp_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-icmp'
+api_call_object_plural_version = 'services-icmp'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceIcmpFacts(object):
+ module = cp_mgmt_service_icmp_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other.py
new file mode 100644
index 00000000..993481cc
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other.py
@@ -0,0 +1,133 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_other
+
+OBJECT = {
+ "name": "New_Service_1",
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "ip_protocol": 51,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_Service_1",
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "ip_protocol": 51,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_Service_1",
+ "color": "blue",
+ "aggressive_aging": {
+ "default_timeout": 3600
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_other.api_call'
+api_call_object = 'service-other'
+
+
+class TestCheckpointServiceOther(object):
+ module = cp_mgmt_service_other
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other_facts.py
new file mode 100644
index 00000000..ea8af4e1
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_other_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_other_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-other'
+api_call_object_plural_version = 'services-other'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceOtherFacts(object):
+ module = cp_mgmt_service_other_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc.py
new file mode 100644
index 00000000..da12b433
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc.py
@@ -0,0 +1,115 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_rpc
+
+OBJECT = {
+ "name": "New_RPC_Service_1",
+ "program_number": 5669,
+ "keep_connections_open_after_policy_installation": False
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_RPC_Service_1",
+ "program_number": 5669,
+ "keep_connections_open_after_policy_installation": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_RPC_Service_1",
+ "color": "blue",
+ "program_number": 5656
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_RPC_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_rpc.api_call'
+api_call_object = 'service-rpc'
+
+
+class TestCheckpointServiceRpc(object):
+ module = cp_mgmt_service_rpc
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc_facts.py
new file mode 100644
index 00000000..88aa379e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_rpc_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_rpc_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-rpc'
+api_call_object_plural_version = 'services-rpc'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceRpcFacts(object):
+ module = cp_mgmt_service_rpc_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp.py
new file mode 100644
index 00000000..70296bc4
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp.py
@@ -0,0 +1,134 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_sctp
+
+OBJECT = {
+ "name": "New_SCTP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_SCTP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_SCTP_Service_1",
+ "color": "blue",
+ "port": 5656,
+ "aggressive_aging": {
+ "default_timeout": 3600
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_SCTP_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_sctp.api_call'
+api_call_object = 'service-sctp'
+
+
+class TestCheckpointServiceSctp(object):
+ module = cp_mgmt_service_sctp
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp_facts.py
new file mode 100644
index 00000000..fe05693d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_sctp_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_sctp_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-sctp'
+api_call_object_plural_version = 'services-sctp'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceSctpFacts(object):
+ module = cp_mgmt_service_sctp_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp.py
new file mode 100644
index 00000000..347606f0
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp.py
@@ -0,0 +1,134 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_tcp
+
+OBJECT = {
+ "name": "New_TCP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_TCP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_TCP_Service_1",
+ "color": "blue",
+ "port": 5656,
+ "aggressive_aging": {
+ "default_timeout": 3600
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_TCP_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_tcp.api_call'
+api_call_object = 'service-tcp'
+
+
+class TestCheckpointServiceTcp(object):
+ module = cp_mgmt_service_tcp
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp_facts.py
new file mode 100644
index 00000000..25c087db
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_tcp_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_tcp_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-tcp'
+api_call_object_plural_version = 'services-tcp'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceTcpFacts(object):
+ module = cp_mgmt_service_tcp_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp.py
new file mode 100644
index 00000000..c8c80340
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp.py
@@ -0,0 +1,137 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_udp
+
+OBJECT = {
+ "name": "New_UDP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ },
+ "accept_replies": False
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_UDP_Service_1",
+ "port": 5669,
+ "keep_connections_open_after_policy_installation": False,
+ "session_timeout": 0,
+ "match_for_any": True,
+ "sync_connections_on_cluster": True,
+ "aggressive_aging": {
+ "enable": True,
+ "timeout": 360,
+ "use_default_timeout": False
+ },
+ "accept_replies": False
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_UDP_Service_1",
+ "color": "blue",
+ "port": 5656,
+ "aggressive_aging": {
+ "default_timeout": 3600
+ },
+ "accept_replies": True
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_UDP_Service_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_service_udp.api_call'
+api_call_object = 'service-udp'
+
+
+class TestCheckpointServiceUdp(object):
+ module = cp_mgmt_service_udp
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp_facts.py
new file mode 100644
index 00000000..f213be30
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_service_udp_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_service_udp_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'service-udp'
+api_call_object_plural_version = 'services-udp'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointServiceUdpFacts(object):
+ module = cp_mgmt_service_udp_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_session_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_session_facts.py
new file mode 100644
index 00000000..88485836
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_session_facts.py
@@ -0,0 +1,80 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_session_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {}
+
+api_call_object = 'session'
+api_call_object_plural_version = 'sessions'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointSessionFacts(object):
+ module = cp_mgmt_session_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_nat_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_nat_rule.py
new file mode 100644
index 00000000..9defa2bc
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_nat_rule.py
@@ -0,0 +1,75 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_set_nat_rule
+
+PAYLOAD = {
+ "package": "standard",
+ "enabled": False,
+ "comments": "rule for RND members RNDNetwork-> RND to Internal Network",
+ "original_service": "ssh_version_2",
+ "original_source": "Any",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'set-nat-rule'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointSetNatRule(object):
+ module = cp_mgmt_set_nat_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_session.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_session.py
new file mode 100644
index 00000000..10886f46
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_set_session.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible.modules.network.check_point import cp_mgmt_set_session
+
+PAYLOAD = {
+ "description": "Session to work on ticket number CR00323665",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'set-session'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointSetSession(object):
+ module = cp_mgmt_set_session
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_access_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_access_section.py
new file mode 100644
index 00000000..78af3cde
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_access_section.py
@@ -0,0 +1,72 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_show_access_section
+
+PAYLOAD = {
+ "layer": "Network",
+ "name": "New Section 1",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'show-access-section'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointShowAccessSection(object):
+ module = cp_mgmt_show_access_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_https_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_https_section.py
new file mode 100644
index 00000000..91080ea5
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_https_section.py
@@ -0,0 +1,72 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_show_https_section
+
+PAYLOAD = {
+ "layer": "Default Layer",
+ "name": "New Section 1",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'show-https-section'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointShowHttpsSection(object):
+ module = cp_mgmt_show_https_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_logs.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_logs.py
new file mode 100644
index 00000000..ca87d46b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_logs.py
@@ -0,0 +1,75 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_show_logs
+
+PAYLOAD = {
+ "new_query": {
+ "filter": "blade:\"Threat Emulation\"",
+ "time_frame": "today",
+ "max_logs_per_request": "2"
+ },
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'show-logs'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointShowLogs(object):
+ module = cp_mgmt_show_logs
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_nat_section.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_nat_section.py
new file mode 100644
index 00000000..41b0d22a
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_nat_section.py
@@ -0,0 +1,72 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_show_nat_section
+
+PAYLOAD = {
+ "package": "standard",
+ "name": "New Section 1",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'show-nat-section'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointShowNatSection(object):
+ module = cp_mgmt_show_nat_section
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_software_package_details.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_software_package_details.py
new file mode 100644
index 00000000..71f58187
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_show_software_package_details.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_show_software_package_details
+
+PAYLOAD = {
+ "name": "Check_Point_R80_40_JHF_MCD_DEMO_019_MAIN_Bundle_T1_VISIBLE_FULL.tgz",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'show-software-package-details'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointShowSoftwarePackageDetails(object):
+ module = cp_mgmt_show_software_package_details
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway.py
new file mode 100644
index 00000000..7dce34d8
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway.py
@@ -0,0 +1,117 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_simple_gateway
+
+OBJECT = {
+ "name": "gw1",
+ "ip_address": "192.0.2.1"
+}
+
+CREATE_PAYLOAD = {
+ "name": "gw1",
+ "ip_address": "192.0.2.1"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "gw1",
+ "ips": True,
+ "application_control": True,
+ "url_filtering": True,
+ "anti_bot": True,
+ "anti_virus": True,
+ "threat_emulation": True
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "gw1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_simple_gateway.api_call'
+api_call_object = 'simple-gateway'
+
+
+class TestCheckpointSimpleGateway(object):
+ module = cp_mgmt_simple_gateway
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway_facts.py
new file mode 100644
index 00000000..f89d476d
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_simple_gateway_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_simple_gateway_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'simple-gateway'
+api_call_object_plural_version = 'simple-gateways'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointSimpleGatewayFacts(object):
+ module = cp_mgmt_simple_gateway_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag.py
new file mode 100644
index 00000000..5f2e7c0e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag.py
@@ -0,0 +1,117 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_tag
+
+OBJECT = {
+ "name": "My New Tag1",
+ "tags": [
+ "tag1",
+ "tag2"
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "name": "My New Tag1",
+ "tags": [
+ "tag1",
+ "tag2"
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "My New Tag1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "My New Tag1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_tag.api_call'
+api_call_object = 'tag'
+
+
+class TestCheckpointTag(object):
+ module = cp_mgmt_tag
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag_facts.py
new file mode 100644
index 00000000..cb41722b
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_tag_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_tag_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'tag'
+api_call_object_plural_version = 'tags'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointTagFacts(object):
+ module = cp_mgmt_tag_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception.py
new file mode 100644
index 00000000..d9f4e183
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception.py
@@ -0,0 +1,119 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_exception
+
+OBJECT = {
+ "layer": "New Layer 1",
+ "name": "Exception Rule",
+ "track": "Log",
+ "rule_name": "First rule",
+ "protected_scope": "All_Internet"
+}
+
+CREATE_PAYLOAD = {
+ "layer": "New Layer 1",
+ "name": "Exception Rule",
+ "track": "Log",
+ "rule_name": "First rule",
+ "protected_scope": "All_Internet"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "Exception Rule",
+ "layer": "New Layer 1",
+ "rule_name": "First rule",
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "Exception Rule",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_threat_exception.api_call'
+api_call_object = 'threat-exception'
+
+
+class TestCheckpointThreatException(object):
+ module = cp_mgmt_threat_exception
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception_facts.py
new file mode 100644
index 00000000..dd4881d0
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_exception_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_exception_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'threat-exception'
+api_call_object_plural_version = 'threat-rule-exception-rulebase'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointThreatExceptionFacts(object):
+ module = cp_mgmt_threat_exception_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator.py
new file mode 100644
index 00000000..e004acc5
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator.py
@@ -0,0 +1,145 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_indicator
+
+OBJECT = {
+ "name": "My_Indicator",
+ "observables": [
+ {
+ "name": "My_Observable",
+ "mail-to": "someone@somewhere.com",
+ "confidence": "medium",
+ "severity": "low",
+ "product": "AV"
+ }
+ ],
+ "action": "Inactive",
+ "profile_overrides": [
+ {
+ "profile": "My_Profile",
+ "action": "detect"
+ }
+ ],
+ "ignore_warnings": True
+}
+
+CREATE_PAYLOAD = {
+ "name": "My_Indicator",
+ "observables": [
+ {
+ "name": "My_Observable",
+ "mail-to": "someone@somewhere.com",
+ "confidence": "medium",
+ "severity": "low",
+ "product": "AV"
+ }
+ ],
+ "action": "Inactive",
+ "profile_overrides": [
+ {
+ "profile": "My_Profile",
+ "action": "detect"
+ }
+ ],
+ "ignore_warnings": True
+}
+
+UPDATE_PAYLOAD = {
+ "name": "My_Indicator",
+ "action": "Inactive",
+ "ignore_warnings": True
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "My_Indicator",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_threat_indicator.api_call'
+api_call_object = 'threat-indicator'
+
+
+class TestCheckpointThreatIndicator(object):
+ module = cp_mgmt_threat_indicator
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator_facts.py
new file mode 100644
index 00000000..12ec3d5c
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_indicator_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_indicator_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'threat-indicator'
+api_call_object_plural_version = 'threat-indicators'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointThreatIndicatorFacts(object):
+ module = cp_mgmt_threat_indicator_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer.py
new file mode 100644
index 00000000..c10c2584
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer.py
@@ -0,0 +1,109 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_layer
+
+OBJECT = {
+ "name": "New Layer 1"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Layer 1"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Layer 1"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Layer 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_threat_layer.api_call'
+api_call_object = 'threat-layer'
+
+
+class TestCheckpointThreatLayer(object):
+ module = cp_mgmt_threat_layer
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer_facts.py
new file mode 100644
index 00000000..25892596
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_layer_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_layer_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'threat-layer'
+api_call_object_plural_version = 'threat-layers'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointThreatLayerFacts(object):
+ module = cp_mgmt_threat_layer_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile.py
new file mode 100644
index 00000000..b786d052
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile.py
@@ -0,0 +1,150 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_profile
+
+OBJECT = {
+ "name": "New Profile 1",
+ "ips": True,
+ "active_protections_performance_impact": "low",
+ "active_protections_severity": "Critical",
+ "confidence_level_medium": "Inactive",
+ "confidence_level_high": "Inactive",
+ "threat_emulation": True,
+ "anti_virus": True,
+ "anti_bot": True,
+ "ips_settings": {
+ "newly_updated_protections": "staging",
+ "exclude_protection_with_performance_impact": True,
+ "exclude_protection_with_performance_impact_mode": "high or lower"
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Profile 1",
+ "ips": True,
+ "active_protections_performance_impact": "low",
+ "active_protections_severity": "Critical",
+ "confidence_level_medium": "Inactive",
+ "confidence_level_high": "Inactive",
+ "threat_emulation": True,
+ "anti_virus": True,
+ "anti_bot": True,
+ "ips_settings": {
+ "newly_updated_protections": "staging",
+ "exclude_protection_with_performance_impact": True,
+ "exclude_protection_with_performance_impact_mode": "high or lower"
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Profile 1",
+ "comments": "update recommended profile",
+ "ips": False,
+ "active_protections_performance_impact": "low",
+ "active_protections_severity": "Critical",
+ "confidence_level_low": "Inactive",
+ "confidence_level_medium": "Inactive",
+ "confidence_level_high": "Inactive",
+ "threat_emulation": True,
+ "anti_virus": False,
+ "anti_bot": True,
+ "ips_settings": {
+ "newly_updated_protections": "active",
+ "exclude_protection_with_performance_impact": True,
+ "exclude_protection_with_performance_impact_mode": "high or lower"
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Profile 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_threat_profile.api_call'
+api_call_object = 'threat-profile'
+
+
+class TestCheckpointThreatProfile(object):
+ module = cp_mgmt_threat_profile
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile_facts.py
new file mode 100644
index 00000000..7ab8f8e3
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_profile_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_profile_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'threat-profile'
+api_call_object_plural_version = 'threat-profiles'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointThreatProfileFacts(object):
+ module = cp_mgmt_threat_profile_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_protection_override.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_protection_override.py
new file mode 100644
index 00000000..43572141
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_protection_override.py
@@ -0,0 +1,79 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_protection_override
+
+PAYLOAD = {
+ "name": "FTP Commands",
+ "overrides": [
+ {
+ "profile": "New Profile 1",
+ "action": "inactive",
+ "track": "None",
+ "capture-packets": True
+ }
+ ],
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'set-threat-protection'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointThreatProtectionOverride(object):
+ module = cp_mgmt_threat_protection_override
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule.py
new file mode 100644
index 00000000..b300b024
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule.py
@@ -0,0 +1,124 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_rule
+
+OBJECT = {
+ "layer": "New Layer 1",
+ "name": "First threat rule",
+ "comments": "",
+ "track": "None",
+ "protected_scope": "All_Internet",
+ "install_on": "Policy Targets"
+}
+
+CREATE_PAYLOAD = {
+ "layer": "New Layer 1",
+ "name": "First threat rule",
+ "comments": "",
+ "track": "None",
+ "protected_scope": "All_Internet",
+ "install_on": "Policy Targets"
+}
+
+UPDATE_PAYLOAD = {
+ "layer": "New Layer 1",
+ "comments": "commnet for the first rule",
+ "action": "New Profile 1",
+ "name": "First threat rule",
+ "protected_scope": "All_Internet",
+ "install_on": "Policy Targets"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "First threat rule",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_threat_rule.api_call'
+api_call_object = 'threat-rule'
+
+
+class TestCheckpointThreatRule(object):
+ module = cp_mgmt_threat_rule
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule_facts.py
new file mode 100644
index 00000000..13491cbe
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_threat_rule_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_threat_rule_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'threat-rule'
+api_call_object_plural_version = 'threat-rulebase'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointThreatRuleFacts(object):
+ module = cp_mgmt_threat_rule_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time.py
new file mode 100644
index 00000000..c1f336d9
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time.py
@@ -0,0 +1,184 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_time
+
+OBJECT = {
+ "name": "timeObject1",
+ "end": {
+ "date": "24-Nov-2014",
+ "time": "21:22"
+ },
+ "recurrence": {
+ "pattern": "Daily",
+ "month": "Any",
+ "weekdays": [
+ "Sun",
+ "Mon"
+ ],
+ "days": [
+ "1"
+ ]
+ },
+ "start_now": True,
+ "end_never": False,
+ "hours_ranges": [
+ {
+ "from": "00:00",
+ "to": "00:00",
+ "enabled": True,
+ "index": 1
+ },
+ {
+ "from": "00:00",
+ "to": "00:00",
+ "enabled": False,
+ "index": 2
+ }
+ ]
+}
+
+CREATE_PAYLOAD = {
+ "name": "timeObject1",
+ "end": {
+ "date": "24-Nov-2014",
+ "time": "21:22"
+ },
+ "recurrence": {
+ "pattern": "Daily",
+ "month": "Any",
+ "weekdays": [
+ "Sun",
+ "Mon"
+ ],
+ "days": [
+ "1"
+ ]
+ },
+ "start_now": True,
+ "end_never": False,
+ "hours_ranges": [
+ {
+ "from": "00:00",
+ "to": "00:00",
+ "enabled": True,
+ "index": 1
+ },
+ {
+ "from": "00:00",
+ "to": "00:00",
+ "enabled": False,
+ "index": 2
+ }
+ ]
+}
+
+UPDATE_PAYLOAD = {
+ "name": "timeObject1",
+ "recurrence": {
+ "pattern": "Weekly",
+ "weekdays": [
+ "Fri"
+ ],
+ "month": "Any"
+ },
+ "hours_ranges": [
+ {
+ "from": "00:22",
+ "to": "00:33"
+ }
+ ]
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "timeObject1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_time.api_call'
+api_call_object = 'time'
+
+
+class TestCheckpointTime(object):
+ module = cp_mgmt_time
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time_facts.py
new file mode 100644
index 00000000..c44c962e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_time_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_time_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'time'
+api_call_object_plural_version = 'times'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointTimeFacts(object):
+ module = cp_mgmt_time_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_uninstall_software_package.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_uninstall_software_package.py
new file mode 100644
index 00000000..09bb5c37
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_uninstall_software_package.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_uninstall_software_package
+
+PAYLOAD = {
+ "name": "Check_Point_R80_40_JHF_MCD_DEMO_019_MAIN_Bundle_T1_VISIBLE_FULL.tgz",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'uninstall-software-package'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointUninstallSoftwarePackage(object):
+ module = cp_mgmt_uninstall_software_package
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_policy.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_policy.py
new file mode 100644
index 00000000..bd708bff
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_policy.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_verify_policy
+
+PAYLOAD = {
+ "policy_package": "standard",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'verify-policy'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointVerifyPolicy(object):
+ module = cp_mgmt_verify_policy
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_software_package.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_software_package.py
new file mode 100644
index 00000000..8a89e42f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_verify_software_package.py
@@ -0,0 +1,71 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_verify_software_package
+
+PAYLOAD = {
+ "name": "Check_Point_R80_40_JHF_MCD_DEMO_019_MAIN_Bundle_T1_VISIBLE_FULL.tgz",
+ "wait_for_task": False
+}
+
+RETURN_PAYLOAD = {
+ "task-id": "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+}
+
+command = 'verify-software-package'
+failure_msg = '{command failed}'
+
+
+class TestCheckpointVerifySoftwarePackage(object):
+ module = cp_mgmt_verify_software_package
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_command(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, RETURN_PAYLOAD)
+ result = self._run_module(PAYLOAD)
+
+ assert result['changed']
+ assert RETURN_PAYLOAD == result[command]
+
+ def test_command_fail(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed.py
new file mode 100644
index 00000000..82ce2929
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed.py
@@ -0,0 +1,142 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_vpn_community_meshed
+
+OBJECT = {
+ "name": "New_VPN_Community_Meshed_1",
+ "encryption_method": "prefer ikev2 but support ikev1",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_VPN_Community_Meshed_1",
+ "encryption_method": "prefer ikev2 but support ikev1",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_VPN_Community_Meshed_1",
+ "encryption_method": "ikev2 only",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_VPN_Community_Meshed_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_vpn_community_meshed.api_call'
+api_call_object = 'vpn-community-meshed'
+
+
+class TestCheckpointVpnCommunityMeshed(object):
+ module = cp_mgmt_vpn_community_meshed
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed_facts.py
new file mode 100644
index 00000000..2b0b8404
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_meshed_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_vpn_community_meshed_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'vpn-community-meshed'
+api_call_object_plural_version = 'vpn-communities-meshed'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointVpnCommunityMeshedFacts(object):
+ module = cp_mgmt_vpn_community_meshed_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star.py
new file mode 100644
index 00000000..5bea660f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star.py
@@ -0,0 +1,148 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_vpn_community_star
+
+OBJECT = {
+ "name": "New_VPN_Community_Star_1",
+ "center_gateways": [
+ "Second_Security_Gateway"
+ ],
+ "encryption_method": "prefer ikev2 but support ikev1",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+CREATE_PAYLOAD = {
+ "name": "New_VPN_Community_Star_1",
+ "center_gateways": [
+ "Second_Security_Gateway"
+ ],
+ "encryption_method": "prefer ikev2 but support ikev1",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New_VPN_Community_Star_1",
+ "encryption_method": "ikev2 only",
+ "encryption_suite": "custom",
+ "ike_phase_1": {
+ "data_integrity": "sha1",
+ "encryption_algorithm": "aes-128",
+ "diffie_hellman_group": "group-1"
+ },
+ "ike_phase_2": {
+ "data_integrity": "aes-xcbc",
+ "encryption_algorithm": "aes-gcm-128"
+ }
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New_VPN_Community_Star_1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_vpn_community_star.api_call'
+api_call_object = 'vpn-community-star'
+
+
+class TestCheckpointVpnCommunityStar(object):
+ module = cp_mgmt_vpn_community_star
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star_facts.py
new file mode 100644
index 00000000..34a2d1dc
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_vpn_community_star_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_vpn_community_star_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'vpn-community-star'
+api_call_object_plural_version = 'vpn-communities-star'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointVpnCommunityStarFacts(object):
+ module = cp_mgmt_vpn_community_star_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard.py
new file mode 100644
index 00000000..c0a5090e
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard.py
@@ -0,0 +1,116 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_wildcard
+
+OBJECT = {
+ "name": "New Wildcard 1",
+ "ipv4_address": "192.168.2.1",
+ "ipv4_mask_wildcard": "0.0.0.128"
+}
+
+CREATE_PAYLOAD = {
+ "name": "New Wildcard 1",
+ "ipv4_address": "192.168.2.1",
+ "ipv4_mask_wildcard": "0.0.0.128"
+}
+
+UPDATE_PAYLOAD = {
+ "name": "New Wildcard 1",
+ "color": "blue",
+ "ipv6_address": "2001:db8::1111",
+ "ipv6_mask_wildcard": "ffff:ffff::f0f0"
+}
+
+OBJECT_AFTER_UPDATE = UPDATE_PAYLOAD
+
+DELETE_PAYLOAD = {
+ "name": "New Wildcard 1",
+ "state": "absent"
+}
+
+function_path = 'ansible_collections.check_point.mgmt.plugins.modules.cp_mgmt_wildcard.api_call'
+api_call_object = 'wildcard'
+
+
+class TestCheckpointWildcard(object):
+ module = cp_mgmt_wildcard
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_create(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT.items() == result[api_call_object].items()
+
+ def test_create_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT}
+ result = self._run_module(CREATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_update(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert result['changed']
+ assert OBJECT_AFTER_UPDATE.items() == result[api_call_object].items()
+
+ def test_update_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False, api_call_object: OBJECT_AFTER_UPDATE}
+ result = self._run_module(UPDATE_PAYLOAD)
+
+ assert not result['changed']
+
+ def test_delete(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': True}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert result['changed']
+
+ def test_delete_idempotent(self, mocker, connection_mock):
+ mock_function = mocker.patch(function_path)
+ mock_function.return_value = {'changed': False}
+ result = self._run_module(DELETE_PAYLOAD)
+
+ assert not result['changed']
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard_facts.py b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard_facts.py
new file mode 100644
index 00000000..a16c3fe8
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/modules/test_cp_mgmt_wildcard_facts.py
@@ -0,0 +1,82 @@
+# Ansible module to manage CheckPoint Firewall (c) 2019
+#
+# 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
+
+import pytest
+from units.modules.utils import set_module_args, exit_json, fail_json, AnsibleExitJson
+
+from ansible.module_utils import basic
+from ansible_collections.check_point.mgmt.plugins.modules import cp_mgmt_wildcard_facts
+
+OBJECT = {
+ "from": 1,
+ "to": 1,
+ "total": 6,
+ "objects": [
+ "53de74b7-8f19-4cbe-99fc-a81ef0759bad"
+ ]
+}
+
+SHOW_PLURAL_PAYLOAD = {
+ 'limit': 1,
+ 'details_level': 'uid'
+}
+
+SHOW_SINGLE_PAYLOAD = {
+ 'name': 'object_which_is_not_exist'
+}
+
+api_call_object = 'wildcard'
+api_call_object_plural_version = 'wildcards'
+failure_msg = '''{u'message': u'Requested object [object_which_is_not_exist] not found', u'code': u'generic_err_object_not_found'}'''
+
+
+class TestCheckpointWildcardFacts(object):
+ module = cp_mgmt_wildcard_facts
+
+ @pytest.fixture(autouse=True)
+ def module_mock(self, mocker):
+ return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
+
+ @pytest.fixture
+ def connection_mock(self, mocker):
+ connection_class_mock = mocker.patch('ansible.module_utils.network.checkpoint.checkpoint.Connection')
+ return connection_class_mock.return_value
+
+ def test_show_single_object_which_is_not_exist(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (404, failure_msg)
+ try:
+ result = self._run_module(SHOW_SINGLE_PAYLOAD)
+ except Exception as e:
+ result = e.args[0]
+
+ assert result['failed']
+ assert 'Checkpoint device returned error 404 with message ' + failure_msg == result['msg']
+
+ def test_show_few_objects(self, mocker, connection_mock):
+ connection_mock.send_request.return_value = (200, OBJECT)
+ result = self._run_module(SHOW_PLURAL_PAYLOAD)
+
+ assert not result['changed']
+ assert OBJECT == result['ansible_facts'][api_call_object_plural_version]
+
+ def _run_module(self, module_args):
+ set_module_args(module_args)
+ with pytest.raises(AnsibleExitJson) as ex:
+ self.module.main()
+ return ex.value.args[0]
diff --git a/ansible_collections/check_point/mgmt/tests/units/plugins/httpapi/test_checkpoint.py b/ansible_collections/check_point/mgmt/tests/units/plugins/httpapi/test_checkpoint.py
new file mode 100644
index 00000000..32ac0b0f
--- /dev/null
+++ b/ansible_collections/check_point/mgmt/tests/units/plugins/httpapi/test_checkpoint.py
@@ -0,0 +1,86 @@
+# (c) 2018 Red Hat Inc.
+# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
+
+from __future__ import (absolute_import, division, print_function)
+__metaclass__ = type
+
+import json
+
+from ansible.module_utils.six.moves.urllib.error import HTTPError
+from units.compat import mock
+from units.compat import unittest
+
+from ansible.errors import AnsibleConnectionFailure
+from ansible.module_utils.connection import ConnectionError
+from ansible.module_utils.six import BytesIO, StringIO
+from ansible_collections.check_point.mgmt.plugins.httpapi.checkpoint import HttpApi
+
+EXPECTED_BASE_HEADERS = {
+ 'Content-Type': 'application/json'
+}
+
+
+class FakeCheckpointHttpApiPlugin(HttpApi):
+ def __init__(self, conn):
+ super(FakeCheckpointHttpApiPlugin, self).__init__(conn)
+ self.hostvars = {
+ 'domain': None
+ }
+
+ def get_option(self, option):
+ return self.hostvars[option]
+
+ def set_option(self, option, value):
+ self.hostvars[option] = value
+
+
+class TestCheckpointHttpApi(unittest.TestCase):
+
+ def setUp(self):
+ self.connection_mock = mock.Mock()
+ self.checkpoint_plugin = FakeCheckpointHttpApiPlugin(self.connection_mock)
+ self.checkpoint_plugin._load_name = 'httpapi'
+
+ def test_login_raises_exception_when_username_and_password_are_not_provided(self):
+ with self.assertRaises(AnsibleConnectionFailure) as res:
+ self.checkpoint_plugin.login(None, None)
+ assert 'Username and password are required' in str(res.exception)
+
+ def test_login_raises_exception_when_invalid_response(self):
+ self.connection_mock.send.return_value = self._connection_response(
+ {'NOSIDKEY': 'NOSIDVALUE'}
+ )
+
+ with self.assertRaises(ConnectionError) as res:
+ self.checkpoint_plugin.login('foo', 'bar')
+
+ assert 'Server returned response without token info during connection authentication' in str(res.exception)
+
+ def test_send_request_should_return_error_info_when_http_error_raises(self):
+ self.connection_mock.send.side_effect = HTTPError('http://testhost.com', 500, '', {},
+ StringIO('{"errorMessage": "ERROR"}'))
+
+ resp = self.checkpoint_plugin.send_request('/test', None)
+
+ assert resp == (500, {'errorMessage': 'ERROR'})
+
+ def test_login_to_global_domain(self):
+ temp_domain = self.checkpoint_plugin.hostvars['domain']
+ self.checkpoint_plugin.hostvars['domain'] = 'test_domain'
+ self.connection_mock.send.return_value = self._connection_response(
+ {'sid': 'SID', 'uid': 'UID'}
+ )
+
+ self.checkpoint_plugin.login('USERNAME', 'PASSWORD')
+
+ self.connection_mock.send.assert_called_once_with('/web_api/login', mock.ANY, headers=mock.ANY,
+ method=mock.ANY)
+ self.checkpoint_plugin.hostvars['domain'] = temp_domain
+
+ @staticmethod
+ def _connection_response(response, status=200):
+ response_mock = mock.Mock()
+ response_mock.getcode.return_value = status
+ response_text = json.dumps(response) if type(response) is dict else response
+ response_data = BytesIO(response_text.encode() if response_text else ''.encode())
+ return response_mock, response_data