mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
FortiManager Plugin Module Conversion: fmgr_secprof_dns (#52771)
* Auto Commit for: fmgr_secprof_dns * Auto Commit for: fmgr_secprof_dns
This commit is contained in:
committed by
Nilashish Chakraborty
parent
e8c983155c
commit
ff368ff55d
@@ -1,76 +1,45 @@
|
||||
{
|
||||
"fmgr_dnsfilter_profile_addsetdelete": [
|
||||
{
|
||||
"paramgram_used": {
|
||||
"comment": "Created by Ansible Module TEST",
|
||||
"ftgd-dns": {
|
||||
"options": null,
|
||||
"filters": {
|
||||
"action": null,
|
||||
"category": null,
|
||||
"log": null
|
||||
}
|
||||
},
|
||||
"name": "Ansible_DNS_Profile",
|
||||
"adom": "root",
|
||||
"redirect-portal": null,
|
||||
"sdns-ftgd-err-log": null,
|
||||
"youtube-restrict": null,
|
||||
"sdns-domain-log": null,
|
||||
"domain-filter": {
|
||||
"domain-filter-table": null
|
||||
},
|
||||
"log-all-domain": null,
|
||||
"mode": "delete",
|
||||
"block-botnet": null,
|
||||
"safe-search": null,
|
||||
"external-ip-blocklist": null,
|
||||
"block-action": null
|
||||
},
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/dnsfilter/profile/Ansible_DNS_Profile"
|
||||
},
|
||||
"post_method": "delete"
|
||||
},
|
||||
{
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/dnsfilter/profile"
|
||||
},
|
||||
"paramgram_used": {
|
||||
"comment": "Created by Ansible Module TEST",
|
||||
"ftgd-dns": {
|
||||
"options": null,
|
||||
"filters": {
|
||||
"action": null,
|
||||
"category": null,
|
||||
"log": null
|
||||
}
|
||||
},
|
||||
"adom": "root",
|
||||
"youtube-restrict": null,
|
||||
"sdns-domain-log": null,
|
||||
"block-botnet": null,
|
||||
"external-ip-blocklist": null,
|
||||
"block-action": "block",
|
||||
"name": "Ansible_DNS_Profile",
|
||||
"redirect-portal": null,
|
||||
"sdns-ftgd-err-log": null,
|
||||
"safe-search": null,
|
||||
"domain-filter": {
|
||||
"domain-filter-table": null
|
||||
},
|
||||
"log-all-domain": null,
|
||||
"mode": "set"
|
||||
},
|
||||
"post_method": "set"
|
||||
}
|
||||
]
|
||||
"fmgr_dnsfilter_profile_modify": [
|
||||
{
|
||||
"raw_response": {
|
||||
"status": {
|
||||
"message": "OK",
|
||||
"code": 0
|
||||
},
|
||||
"url": "/pm/config/adom/root/obj/dnsfilter/profile"
|
||||
},
|
||||
"datagram_sent": {
|
||||
"comment": "Created by Ansible Module TEST",
|
||||
"name": "Ansible_DNS_Profile",
|
||||
"block-action": "block"
|
||||
},
|
||||
"paramgram_used": {
|
||||
"comment": "Created by Ansible Module TEST",
|
||||
"ftgd-dns": {
|
||||
"options": null,
|
||||
"filters": {
|
||||
"action": null,
|
||||
"category": null,
|
||||
"log": null
|
||||
}
|
||||
},
|
||||
"adom": "root",
|
||||
"youtube-restrict": null,
|
||||
"sdns-domain-log": null,
|
||||
"block-botnet": null,
|
||||
"external-ip-blocklist": null,
|
||||
"block-action": "block",
|
||||
"name": "Ansible_DNS_Profile",
|
||||
"redirect-portal": null,
|
||||
"sdns-ftgd-err-log": null,
|
||||
"safe-search": null,
|
||||
"domain-filter": {
|
||||
"domain-filter-table": null
|
||||
},
|
||||
"log-all-domain": null,
|
||||
"mode": "set"
|
||||
},
|
||||
"post_method": "set"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ __metaclass__ = type
|
||||
|
||||
import os
|
||||
import json
|
||||
from pyFMG.fortimgr import FortiManager
|
||||
from ansible.module_utils.network.fortimanager.fortimanager import FortiManagerHandler
|
||||
import pytest
|
||||
|
||||
try:
|
||||
@@ -27,8 +27,6 @@ try:
|
||||
except ImportError:
|
||||
pytest.skip("Could not load required modules for testing", allow_module_level=True)
|
||||
|
||||
fmg_instance = FortiManager("1.1.1.1", "admin", "")
|
||||
|
||||
|
||||
def load_fixtures():
|
||||
fixture_path = os.path.join(os.path.dirname(__file__), 'fixtures') + "/{filename}.json".format(
|
||||
@@ -41,33 +39,32 @@ def load_fixtures():
|
||||
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_dns.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)
|
||||
|
||||
|
||||
def test_fmgr_dnsfilter_profile_addsetdelete(fixture_data, mocker):
|
||||
mocker.patch("pyFMG.fortimgr.FortiManager._post_request", side_effect=fixture_data)
|
||||
fmg_instance = FortiManagerHandler(connection_mock, module_mock)
|
||||
|
||||
|
||||
def test_fmgr_dnsfilter_profile_modify(fixture_data, mocker):
|
||||
mocker.patch("ansible.module_utils.network.fortimanager.fortimanager.FortiManagerHandler.process_request",
|
||||
side_effect=fixture_data)
|
||||
# Fixture sets used:###########################
|
||||
|
||||
##################################################
|
||||
# comment: Created by Ansible Module TEST
|
||||
# ftgd-dns: {'options': None, 'filters': {'action': None, 'category': None, 'log': None}}
|
||||
# name: Ansible_DNS_Profile
|
||||
# adom: root
|
||||
# redirect-portal: None
|
||||
# sdns-ftgd-err-log: None
|
||||
# youtube-restrict: None
|
||||
# sdns-domain-log: None
|
||||
# domain-filter: {'domain-filter-table': None}
|
||||
# log-all-domain: None
|
||||
# mode: delete
|
||||
# block-botnet: None
|
||||
# safe-search: None
|
||||
# external-ip-blocklist: None
|
||||
# block-action: None
|
||||
##################################################
|
||||
##################################################
|
||||
# comment: Created by Ansible Module TEST
|
||||
# ftgd-dns: {'options': None, 'filters': {'action': None, 'category': None, 'log': None}}
|
||||
@@ -87,8 +84,5 @@ def test_fmgr_dnsfilter_profile_addsetdelete(fixture_data, mocker):
|
||||
##################################################
|
||||
|
||||
# Test using fixture 1 #
|
||||
output = fmgr_secprof_dns.fmgr_dnsfilter_profile_addsetdelete(fmg_instance, fixture_data[0]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
||||
# Test using fixture 2 #
|
||||
output = fmgr_secprof_dns.fmgr_dnsfilter_profile_addsetdelete(fmg_instance, fixture_data[1]['paramgram_used'])
|
||||
output = fmgr_secprof_dns.fmgr_dnsfilter_profile_modify(fmg_instance, fixture_data[0]['paramgram_used'])
|
||||
assert output['raw_response']['status']['code'] == 0
|
||||
|
||||
Reference in New Issue
Block a user