You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansible/test/units/modules/network/fortimanager/test_fmgr_secprof_web.py

68 lines
2.4 KiB
Python

FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
# 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
FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
import pytest
try:
from ansible.modules.network.fortimanager import fmgr_secprof_web
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])
FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
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_web.Connection')
return connection_class_mock
FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
@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)
FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
def test_fmgr_webfilter_profile_modify(fixture_data, mocker):
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
side_effect=fixture_data)
output = fmgr_secprof_web.fmgr_webfilter_profile_modify(fmg_instance, fixture_data[0]['paramgram_used'])
FortiManager Web Filter Security Profile (#47150) * Initial Commit * Initial Commit * Initial Commit * Fixing syntax errors * After running sanity tests, fixed pylint and pep8 errors * After running sanity tests, fixed pylint and pep8 errors * Fixing more syntax issues * Fixing more syntax issues * Adding username to doc block * PR candidate * PR candidate * fixed pep8 and docs issues * fixed 2.6 function issues * fixed 2.6 function issues part duex * Initial commit for security profile group module * Adding better playbook example to module * Adding another commit to test shippable tests * Fixing shippable errors, pep8 in unit test file and doc block problem in main module * Fixing documentation module error * Fixing pep8 line too long in unit test * Fixing utility function with nested dictionaries * Fixing utility function with pep8 issue * Adding change to allow for multiple list of dictionaries to be submitted via a single playbook * Initial commit for FMG Security Profile Web Application Firewall * adding extra line at bottom for pep8 conditions * Adding descriptions to documentation * Fixing more pep8 issues * New commit for new PR * Removing todo in documentation * Changing module name in documentation to match actual module name * Fixing yaml syntax for long choices list * Fixing yaml syntax for long choices list * Initial commit for fmgr web filter security profile * Fixing pep8 syntax issues * Fixing documentation yaml syntax errors with choices on new lines * Fixing documentation yaml syntax errors, removing Todo comments * Fixing choices additional tab * Fixing choices on multiple lines * Fixing choices on multiple lines * Adding yaml block scalar for multiline choices * Changing YAML syntax for multiline to YAML sequence for choices * Fixing all sanity test errors * Fixing review changes * Adding @ in author names per @Gundalow's request per Ansible's guidelines
6 years ago
assert output['raw_response']['status']['code'] == 0