diff options
author | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:33 +0000 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2020-03-23 11:14:21 -0500 |
commit | 6da1ec1d8caf716b515e2cf8b9dc61fa1d3bfad7 (patch) | |
tree | b5a9f81d835d27c6d61c98b328c68642a739785a /test/units/modules | |
parent | f0cf2c159bd25c2668ffeb8e3d65be9abe098edb (diff) | |
download | ansible-6da1ec1d8caf716b515e2cf8b9dc61fa1d3bfad7.tar.gz |
Migrated to check_point.mgmt
Diffstat (limited to 'test/units/modules')
89 files changed, 0 insertions, 8845 deletions
diff --git a/test/units/modules/network/check_point/test_cp_mgmt_access_layer.py b/test/units/modules/network/check_point/test_cp_mgmt_access_layer.py deleted file mode 100644 index 4c498cf049..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_layer.py +++ /dev/null @@ -1,110 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_access_layer_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_access_layer_facts.py deleted file mode 100644 index a9a2daa6a3..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_layer_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_access_role.py b/test/units/modules/network/check_point/test_cp_mgmt_access_role.py deleted file mode 100644 index 6cad9aab10..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_role.py +++ /dev/null @@ -1,119 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_access_role_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_access_role_facts.py deleted file mode 100644 index f866503f70..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_role_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_access_rule.py b/test/units/modules/network/check_point/test_cp_mgmt_access_rule.py deleted file mode 100644 index 27e12800ca..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_rule.py +++ /dev/null @@ -1,124 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_access_rule_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_access_rule_facts.py deleted file mode 100644 index 1c6eaef945..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_access_rule_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_address_range.py b/test/units/modules/network/check_point/test_cp_mgmt_address_range.py deleted file mode 100644 index ec8c0d9b68..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_address_range.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_address_range_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_address_range_facts.py deleted file mode 100644 index 8861b0590f..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_address_range_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_administrator.py b/test/units/modules/network/check_point/test_cp_mgmt_administrator.py deleted file mode 100644 index 404920caaf..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_administrator.py +++ /dev/null @@ -1,123 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_administrator_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_administrator_facts.py deleted file mode 100644 index 9266808330..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_administrator_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_application_site.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site.py deleted file mode 100644 index bceea1fb0c..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site.py +++ /dev/null @@ -1,136 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_application_site_category.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site_category.py deleted file mode 100644 index ca9e7f0c20..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site_category.py +++ /dev/null @@ -1,112 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_application_site_category_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site_category_facts.py deleted file mode 100644 index eb61f21066..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site_category_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_application_site_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site_facts.py deleted file mode 100644 index 8087de9444..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_application_site_group.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site_group.py deleted file mode 100644 index c1eafc8ed3..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site_group.py +++ /dev/null @@ -1,121 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_application_site_group_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_application_site_group_facts.py deleted file mode 100644 index 20a811c95e..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_application_site_group_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_assign_global_assignment.py b/test/units/modules/network/check_point/test_cp_mgmt_assign_global_assignment.py deleted file mode 100644 index ceb7ae36ec..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_assign_global_assignment.py +++ /dev/null @@ -1,72 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_discard.py b/test/units/modules/network/check_point/test_cp_mgmt_discard.py deleted file mode 100644 index 54612281df..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_discard.py +++ /dev/null @@ -1,70 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_dns_domain.py b/test/units/modules/network/check_point/test_cp_mgmt_dns_domain.py deleted file mode 100644 index 088cafe7cc..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_dns_domain.py +++ /dev/null @@ -1,112 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_dns_domain_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_dns_domain_facts.py deleted file mode 100644 index af4fc8215d..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_dns_domain_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object.py b/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object.py deleted file mode 100644 index c2092a8a0f..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object_facts.py deleted file mode 100644 index c4ab0aaefc..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_dynamic_object_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_exception_group.py b/test/units/modules/network/check_point/test_cp_mgmt_exception_group.py deleted file mode 100644 index d687ef5d48..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_exception_group.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_exception_group_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_exception_group_facts.py deleted file mode 100644 index 15d5dfe344..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_exception_group_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_global_assignment.py b/test/units/modules/network/check_point/test_cp_mgmt_global_assignment.py deleted file mode 100644 index 32c9847c25..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_global_assignment.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_global_assignment_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_global_assignment_facts.py deleted file mode 100644 index 22d88b88a9..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_global_assignment_facts.py +++ /dev/null @@ -1,80 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_group.py b/test/units/modules/network/check_point/test_cp_mgmt_group.py deleted file mode 100644 index 181d56c8f9..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_group.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_group_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_group_facts.py deleted file mode 100644 index 1baefe8778..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_group_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion.py b/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion.py deleted file mode 100644 index f3819394ef..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion_facts.py deleted file mode 100644 index 1fc18b1ec8..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_group_with_exclusion_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_host.py b/test/units/modules/network/check_point/test_cp_mgmt_host.py deleted file mode 100644 index bf855210d9..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_host.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_host_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_host_facts.py deleted file mode 100644 index 1df1963135..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_host_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_install_policy.py b/test/units/modules/network/check_point/test_cp_mgmt_install_policy.py deleted file mode 100644 index 698977fc75..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_install_policy.py +++ /dev/null @@ -1,76 +0,0 @@ -# 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_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/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 deleted file mode 100644 index e9a145cd1b..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_mds_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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_multicast_address_range.py b/test/units/modules/network/check_point/test_cp_mgmt_multicast_address_range.py deleted file mode 100644 index 245fd86aa1..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_multicast_address_range.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_multicast_address_range_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_multicast_address_range_facts.py deleted file mode 100644 index 3b6a7c6f34..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_multicast_address_range_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_network.py b/test/units/modules/network/check_point/test_cp_mgmt_network.py deleted file mode 100644 index 12264fdede..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_network.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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_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.modules.network.check_point.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/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 deleted file mode 100644 index 1b52de3d4b..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_network_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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_package.py b/test/units/modules/network/check_point/test_cp_mgmt_package.py deleted file mode 100644 index e563f3cafb..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_package.py +++ /dev/null @@ -1,133 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_package_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_package_facts.py deleted file mode 100644 index 99d5821a18..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_package_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_publish.py b/test/units/modules/network/check_point/test_cp_mgmt_publish.py deleted file mode 100644 index 4768da0f19..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_publish.py +++ /dev/null @@ -1,70 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_put_file.py b/test/units/modules/network/check_point/test_cp_mgmt_put_file.py deleted file mode 100644 index aeb1bb3c8e..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_put_file.py +++ /dev/null @@ -1,76 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_run_ips_update.py b/test/units/modules/network/check_point/test_cp_mgmt_run_ips_update.py deleted file mode 100644 index 5a4419ff34..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_run_ips_update.py +++ /dev/null @@ -1,70 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_run_script.py b/test/units/modules/network/check_point/test_cp_mgmt_run_script.py deleted file mode 100644 index 50da5d3371..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_run_script.py +++ /dev/null @@ -1,75 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_security_zone.py b/test/units/modules/network/check_point/test_cp_mgmt_security_zone.py deleted file mode 100644 index 1c116d2307..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_security_zone.py +++ /dev/null @@ -1,113 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_security_zone_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_security_zone_facts.py deleted file mode 100644 index da7ee65d5c..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_security_zone_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc.py b/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc.py deleted file mode 100644 index e2d71faa35..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc_facts.py deleted file mode 100644 index e28f32f082..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_dce_rpc_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_group.py b/test/units/modules/network/check_point/test_cp_mgmt_service_group.py deleted file mode 100644 index 3e5427b8d2..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_group.py +++ /dev/null @@ -1,121 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_group_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_group_facts.py deleted file mode 100644 index 2357f96150..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_group_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_icmp.py b/test/units/modules/network/check_point/test_cp_mgmt_service_icmp.py deleted file mode 100644 index 749d3c454d..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_icmp.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6.py b/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6.py deleted file mode 100644 index e23309d026..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6_facts.py deleted file mode 100644 index beb790c362..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_icmp6_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_icmp_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_icmp_facts.py deleted file mode 100644 index 55e2207925..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_icmp_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_other.py b/test/units/modules/network/check_point/test_cp_mgmt_service_other.py deleted file mode 100644 index b7383a1dd9..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_other.py +++ /dev/null @@ -1,133 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_other_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_other_facts.py deleted file mode 100644 index 6e1b0f5056..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_other_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_rpc.py b/test/units/modules/network/check_point/test_cp_mgmt_service_rpc.py deleted file mode 100644 index b8dace2767..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_rpc.py +++ /dev/null @@ -1,115 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_rpc_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_rpc_facts.py deleted file mode 100644 index c87b1b4eb4..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_rpc_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_sctp.py b/test/units/modules/network/check_point/test_cp_mgmt_service_sctp.py deleted file mode 100644 index 6e83111d06..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_sctp.py +++ /dev/null @@ -1,134 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_sctp_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_sctp_facts.py deleted file mode 100644 index 2c66529890..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_sctp_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_tcp.py b/test/units/modules/network/check_point/test_cp_mgmt_service_tcp.py deleted file mode 100644 index be268351e7..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_tcp.py +++ /dev/null @@ -1,134 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_tcp_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_tcp_facts.py deleted file mode 100644 index cdea2d4d29..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_tcp_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_service_udp.py b/test/units/modules/network/check_point/test_cp_mgmt_service_udp.py deleted file mode 100644 index 3018bbb5cc..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_udp.py +++ /dev/null @@ -1,137 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_service_udp_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_service_udp_facts.py deleted file mode 100644 index 2392bcab2b..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_service_udp_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/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 deleted file mode 100644 index b850f869e6..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_session_facts.py +++ /dev/null @@ -1,80 +0,0 @@ -# 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_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_simple_gateway.py b/test/units/modules/network/check_point/test_cp_mgmt_simple_gateway.py deleted file mode 100644 index 5d9a237f62..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_simple_gateway.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_simple_gateway_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_simple_gateway_facts.py deleted file mode 100644 index 9d0abb50a7..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_simple_gateway_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_tag.py b/test/units/modules/network/check_point/test_cp_mgmt_tag.py deleted file mode 100644 index 276c8fad2a..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_tag.py +++ /dev/null @@ -1,117 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_tag_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_tag_facts.py deleted file mode 100644 index 3c3a732a0a..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_tag_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_threat_exception.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_exception.py deleted file mode 100644 index 5ee54a82ef..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_exception.py +++ /dev/null @@ -1,119 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_threat_exception_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_exception_facts.py deleted file mode 100644 index 4fd02263da..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_exception_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/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 deleted file mode 100644 index 6cb952f499..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator.py +++ /dev/null @@ -1,145 +0,0 @@ -# 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_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 deleted file mode 100644 index 1bb975e6da..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_indicator_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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 deleted file mode 100644 index 3cd61a2d23..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_layer.py +++ /dev/null @@ -1,109 +0,0 @@ -# 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_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 deleted file mode 100644 index 0f0494ff9e..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_layer_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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 deleted file mode 100644 index 32f0f030d7..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_profile.py +++ /dev/null @@ -1,150 +0,0 @@ -# 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_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 deleted file mode 100644 index aec240f075..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_profile_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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_threat_protection_override.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_protection_override.py deleted file mode 100644 index 7d668754f8..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_protection_override.py +++ /dev/null @@ -1,79 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_threat_rule.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_rule.py deleted file mode 100644 index 0b3695ea3a..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_rule.py +++ /dev/null @@ -1,124 +0,0 @@ -# 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_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.modules.network.check_point.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/test/units/modules/network/check_point/test_cp_mgmt_threat_rule_facts.py b/test/units/modules/network/check_point/test_cp_mgmt_threat_rule_facts.py deleted file mode 100644 index dae898b7d8..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_threat_rule_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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/test/units/modules/network/check_point/test_cp_mgmt_time.py b/test/units/modules/network/check_point/test_cp_mgmt_time.py deleted file mode 100644 index 3fcd66f9c8..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_time.py +++ /dev/null @@ -1,184 +0,0 @@ -# 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_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 deleted file mode 100644 index 8dcf50d7fd..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_time_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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_verify_policy.py b/test/units/modules/network/check_point/test_cp_mgmt_verify_policy.py deleted file mode 100644 index 0cd161fdaa..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_verify_policy.py +++ /dev/null @@ -1,71 +0,0 @@ -# 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_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/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 deleted file mode 100644 index add64e6d12..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed.py +++ /dev/null @@ -1,142 +0,0 @@ -# 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_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 deleted file mode 100644 index aad6705310..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_meshed_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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 deleted file mode 100644 index 1fe2a88899..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star.py +++ /dev/null @@ -1,148 +0,0 @@ -# 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_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 deleted file mode 100644 index be74f6cb05..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_vpn_community_star_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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 deleted file mode 100644 index 36cef3638d..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_wildcard.py +++ /dev/null @@ -1,116 +0,0 @@ -# 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_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 deleted file mode 100644 index aa78ff064f..0000000000 --- a/test/units/modules/network/check_point/test_cp_mgmt_wildcard_facts.py +++ /dev/null @@ -1,82 +0,0 @@ -# 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_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] |