diff options
author | ftntcorecse <43451990+ftntcorecse@users.noreply.github.com> | 2019-03-05 10:17:51 +0100 |
---|---|---|
committer | Nilashish Chakraborty <nilashishchakraborty8@gmail.com> | 2019-03-05 10:17:51 +0100 |
commit | 73e6f15d64e75a8e0a2f1fab76c85b345126e43d (patch) | |
tree | 1469e98ee156a9097062210124995031c8fbddcb /test | |
parent | Auto Commit for: fmgr_secprof_ips (#53024) (diff) | |
download | ansible-73e6f15d64e75a8e0a2f1fab76c85b345126e43d.tar.xz ansible-73e6f15d64e75a8e0a2f1fab76c85b345126e43d.zip |
Auto Commit for: fmgr_secprof_wanopt (#53023)
Diffstat (limited to 'test')
-rw-r--r-- | test/units/modules/network/fortimanager/fixtures/test_fmgr_secprof_wanopt.json | 162 | ||||
-rw-r--r-- | test/units/modules/network/fortimanager/test_fmgr_secprof_wanopt.py | 72 |
2 files changed, 234 insertions, 0 deletions
diff --git a/test/units/modules/network/fortimanager/fixtures/test_fmgr_secprof_wanopt.json b/test/units/modules/network/fortimanager/fixtures/test_fmgr_secprof_wanopt.json new file mode 100644 index 0000000000..ae9cd041cc --- /dev/null +++ b/test/units/modules/network/fortimanager/fixtures/test_fmgr_secprof_wanopt.json @@ -0,0 +1,162 @@ +{ + "fmgr_wanopt_profile_modify": [ + { + "paramgram_used": { + "ftp": { + "status": null, + "log-traffic": null, + "byte-caching": null, + "prefer-chunking": null, + "secure-tunnel": null, + "port": null, + "tunnel-sharing": null + }, + "http": { + "status": null, + "ssl": null, + "tunnel-non-http": null, + "log-traffic": null, + "byte-caching": null, + "unknown-http-version": null, + "prefer-chunking": null, + "tunnel-sharing": null, + "port": null, + "ssl-port": null, + "secure-tunnel": null + }, + "cifs": { + "status": null, + "log-traffic": null, + "byte-caching": null, + "prefer-chunking": null, + "secure-tunnel": null, + "port": null, + "tunnel-sharing": null + }, + "adom": "root", + "auth-group": null, + "mapi": { + "status": null, + "log-traffic": null, + "byte-caching": null, + "secure-tunnel": null, + "port": null, + "tunnel-sharing": null + }, + "tcp": { + "status": null, + "byte-caching-opt": null, + "ssl": null, + "log-traffic": null, + "byte-caching": null, + "secure-tunnel": null, + "port": null, + "ssl-port": null, + "tunnel-sharing": null + }, + "mode": "delete", + "comments": null, + "transparent": null, + "name": "Ansible_WanOpt_Profile" + }, + "datagram_sent": {}, + "raw_response": { + "status": { + "message": "OK", + "code": 0 + }, + "url": "/pm/config/adom/root/obj/wanopt/profile/Ansible_WanOpt_Profile" + }, + "post_method": "delete" + }, + { + "raw_response": { + "status": { + "message": "OK", + "code": 0 + }, + "url": "/pm/config/adom/root/obj/wanopt/profile" + }, + "datagram_sent": { + "ftp": { + "status": "enable", + "log-traffic": "enable", + "byte-caching": "enable", + "prefer-chunking": "dynamic", + "tunnel-sharing": "private", + "port": 80, + "secure-tunnel": "disable" + }, + "name": "Ansible_WanOpt_Profile", + "cifs": { + "status": "enable", + "log-traffic": "enable", + "byte-caching": "enable", + "prefer-chunking": "dynamic", + "port": 80, + "tunnel-sharing": "private" + }, + "comments": "Created by Ansible", + "transparent": "enable" + }, + "paramgram_used": { + "http": { + "status": null, + "log-traffic": null, + "prefer-chunking": null, + "port": null, + "ssl": null, + "tunnel-non-http": null, + "byte-caching": null, + "unknown-http-version": null, + "secure-tunnel": null, + "ssl-port": null, + "tunnel-sharing": null + }, + "cifs": { + "status": "enable", + "log-traffic": "enable", + "byte-caching": "enable", + "prefer-chunking": "dynamic", + "port": 80, + "tunnel-sharing": "private" + }, + "adom": "root", + "auth-group": null, + "tcp": { + "status": null, + "log-traffic": null, + "byte-caching-opt": null, + "byte-caching": null, + "ssl": null, + "tunnel-sharing": null, + "port": null, + "ssl-port": null, + "secure-tunnel": null + }, + "transparent": "enable", + "ftp": { + "status": "enable", + "log-traffic": "enable", + "byte-caching": "enable", + "prefer-chunking": "dynamic", + "tunnel-sharing": "private", + "port": 80, + "secure-tunnel": "disable" + }, + "name": "Ansible_WanOpt_Profile", + "mapi": { + "status": null, + "log-traffic": null, + "byte-caching": null, + "secure-tunnel": null, + "port": null, + "tunnel-sharing": null + }, + "comments": "Created by Ansible", + "mode": "set" + }, + "post_method": "set" + } + ] +} diff --git a/test/units/modules/network/fortimanager/test_fmgr_secprof_wanopt.py b/test/units/modules/network/fortimanager/test_fmgr_secprof_wanopt.py new file mode 100644 index 0000000000..44949aaf47 --- /dev/null +++ b/test/units/modules/network/fortimanager/test_fmgr_secprof_wanopt.py @@ -0,0 +1,72 @@ +# Copyright 2018 Fortinet, Inc. +# +# This program 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. +# +# This program 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 <https://www.gnu.org/licenses/>. + +# Make coding more python3-ish +from __future__ import (absolute_import, division, print_function) +__metaclass__ = type + +import os +import json +from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler +import pytest + +try: + from ansible.modules.network.fortimanager import fmgr_secprof_wanopt +except ImportError: + pytest.skip("Could not load required modules for testing", allow_module_level=True) + + +def load_fixtures(): + fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format( + filename=os.path.splitext(os.path.basename(__file__))[0]) + try: + with open(fixture_path, "r") as fixture_file: + fixture_data = json.load(fixture_file) + except IOError: + return [] + return [fixture_data] + + +@pytest.fixture(autouse=True) +def module_mock(mocker): + connection_class_mock = mocker.patch('ansible.module_utils.basic.AnsibleModule') + return connection_class_mock + + +@pytest.fixture(autouse=True) +def connection_mock(mocker): + connection_class_mock = mocker.patch('ansible.modules.network.fortimanager.fmgr_secprof_wanopt.Connection') + return connection_class_mock + + +@pytest.fixture(scope="function", params=load_fixtures()) +def fixture_data(request): + func_name = request.function.__name__.replace("test_", "") + return request.param.get(func_name, None) + + +fmg_instance = FortiManagerHandler(connection_mock, module_mock) + + +def test_fmgr_wanopt_profile_modify(fixture_data, mocker): + mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request", + side_effect=fixture_data) + + # Test using fixture 1 # + output = fmgr_secprof_wanopt.fmgr_wanopt_profile_modify(fmg_instance, fixture_data[0]['paramgram_used']) + assert output['raw_response']['status']['code'] == 0 + # Test using fixture 2 # + output = fmgr_secprof_wanopt.fmgr_wanopt_profile_modify(fmg_instance, fixture_data[1]['paramgram_used']) + assert output['raw_response']['status']['code'] == 0 |