From c7f9c3f27e47885680842ffbdb9d97c56db54f2c Mon Sep 17 00:00:00 2001
From: chkp-orso <47325598+chkp-orso@users.noreply.github.com>
Date: Fri, 13 Sep 2019 13:54:29 +0200
Subject: [PATCH] Add unit tests for check_point ansible modules (#62213)
* Update test_cp_mgmt_network.py
* 17 tests
---
.../check_point/test_cp_mgmt_mds_facts.py | 82 ++++++++
.../check_point/test_cp_mgmt_network.py | 14 --
.../check_point/test_cp_mgmt_network_facts.py | 82 ++++++++
.../check_point/test_cp_mgmt_session_facts.py | 80 ++++++++
.../test_cp_mgmt_threat_indicator.py | 145 ++++++++++++++
.../test_cp_mgmt_threat_indicator_facts.py | 82 ++++++++
.../check_point/test_cp_mgmt_threat_layer.py | 109 +++++++++++
.../test_cp_mgmt_threat_layer_facts.py | 82 ++++++++
.../test_cp_mgmt_threat_profile.py | 150 ++++++++++++++
.../test_cp_mgmt_threat_profile_facts.py | 82 ++++++++
.../network/check_point/test_cp_mgmt_time.py | 184 ++++++++++++++++++
.../check_point/test_cp_mgmt_time_facts.py | 82 ++++++++
.../test_cp_mgmt_vpn_community_meshed.py | 142 ++++++++++++++
...test_cp_mgmt_vpn_community_meshed_facts.py | 82 ++++++++
.../test_cp_mgmt_vpn_community_star.py | 148 ++++++++++++++
.../test_cp_mgmt_vpn_community_star_facts.py | 82 ++++++++
.../check_point/test_cp_mgmt_wildcard.py | 116 +++++++++++
.../test_cp_mgmt_wildcard_facts.py | 82 ++++++++
18 files changed, 1812 insertions(+), 14 deletions(-)
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_mds_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_network_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_session_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_indicator.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_indicator_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_layer.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_layer_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_profile.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_threat_profile_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_time.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_time_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star_facts.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_wildcard.py
create mode 100644 test/units/modules/network/check_point/test_cp_mgmt_wildcard_facts.py
diff --git a/test/units/modules/network/check_point/test_cp_mgmt_mds_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_mds_facts.py
new file mode 100644
index 00000000000..e9a145cd1b7
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_network.py b/test/units/modules/network/check_point/test_cp_mgmt_network.py
index d9fdd5be8f0..a3ec15a7adf 100644
--- a/test/units/modules/network/check_point/test_cp_mgmt_network.py
+++ b/test/units/modules/network/check_point/test_cp_mgmt_network.py
@@ -45,13 +45,6 @@ DELETE_PAYLOAD = {'name': 'test_new_network', 'state': 'absent'}
class TestCheckpointNetwork(object):
module = cp_mgmt_network
- checkpoint_argument_spec_for_objects = dict(
- auto_publish_session=dict(type='bool'),
- wait_for_task=dict(type='bool', default=True),
- state=dict(type='str', required=True, choices=['present', 'absent']),
- version=dict(type='str')
- )
-
@pytest.fixture(autouse=True)
def module_mock(self, mocker):
return mocker.patch.multiple(basic.AnsibleModule, exit_json=exit_json, fail_json=fail_json)
@@ -113,10 +106,3 @@ class TestCheckpointNetwork(object):
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/test/units/modules/network/check_point/test_cp_mgmt_network_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_network_facts.py
new file mode 100644
index 00000000000..1b52de3d4b4
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_session_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_session_facts.py
new file mode 100644
index 00000000000..b850f869e66
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator.py
new file mode 100644
index 00000000000..6cb952f4999
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator_facts.py
new file mode 100644
index 00000000000..1bb975e6da0
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_threat_layer.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_layer.py
new file mode 100644
index 00000000000..3cd61a2d23e
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_threat_layer_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_layer_facts.py
new file mode 100644
index 00000000000..0f0494ff9eb
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_threat_profile.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_profile.py
new file mode 100644
index 00000000000..32f0f030d71
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_threat_profile_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_profile_facts.py
new file mode 100644
index 00000000000..aec240f0750
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_time.py b/test/units/modules/network/check_point/test_cp_mgmt_time.py
new file mode 100644
index 00000000000..3fcd66f9c8b
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_time_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_time_facts.py
new file mode 100644
index 00000000000..8dcf50d7fdc
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed.py b/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed.py
new file mode 100644
index 00000000000..add64e6d126
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed_facts.py
new file mode 100644
index 00000000000..aad6705310a
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star.py b/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star.py
new file mode 100644
index 00000000000..1fe2a88899e
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star_facts.py
new file mode 100644
index 00000000000..be74f6cb052
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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/test/units/modules/network/check_point/test_cp_mgmt_wildcard.py b/test/units/modules/network/check_point/test_cp_mgmt_wildcard.py
new file mode 100644
index 00000000000..36cef3638df
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_wildcard_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_wildcard_facts.py
new file mode 100644
index 00000000000..aa78ff064f8
--- /dev/null
+++ b/test/units/modules/network/check_point/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 .
+#
+
+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_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]