예제 #1
0
def test_firewall_policy64_deletion_fails(mocker):
    schema_method_mock = mocker.patch(
        'ansible_collections.ansible.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.schema'
    )

    delete_method_result = {
        'status': 'error',
        'http_method': 'POST',
        'http_status': 500
    }
    delete_method_mock = mocker.patch(
        'ansible_collections.ansible.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.delete',
        return_value=delete_method_result)

    input_data = {
        'username': '******',
        'state': 'absent',
        'firewall_policy64': {
            'action': 'accept',
            'comments': 'test_value_4',
            'dstintf': 'test_value_5',
            'fixedport': 'enable',
            'ippool': 'enable',
            'logtraffic': 'enable',
            'per_ip_shaper': 'test_value_9',
            'permit_any_host': 'enable',
            'policyid': '11',
            'schedule': 'test_value_12',
            'srcintf': 'test_value_13',
            'status': 'enable',
            'tcp_mss_receiver': '15',
            'tcp_mss_sender': '16',
            'traffic_shaper': 'test_value_17',
            'traffic_shaper_reverse': 'test_value_18',
            'uuid': 'test_value_19'
        },
        'vdom': 'root'
    }

    is_error, changed, response = fortios_firewall_policy64.fortios_firewall(
        input_data, fos_instance)

    delete_method_mock.assert_called_with('firewall',
                                          'policy64',
                                          mkey=ANY,
                                          vdom='root')
    schema_method_mock.assert_not_called()
    assert is_error
    assert not changed
    assert response['status'] == 'error'
    assert response['http_status'] == 500
예제 #2
0
def test_firewall_policy64_filter_foreign_attributes(mocker):
    schema_method_mock = mocker.patch(
        'ansible_collections.ansible.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.schema'
    )

    set_method_result = {
        'status': 'success',
        'http_method': 'POST',
        'http_status': 200
    }
    set_method_mock = mocker.patch(
        'ansible_collections.ansible.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.set',
        return_value=set_method_result)

    input_data = {
        'username': '******',
        'state': 'present',
        'firewall_policy64': {
            'random_attribute_not_valid': 'tag',
            'action': 'accept',
            'comments': 'test_value_4',
            'dstintf': 'test_value_5',
            'fixedport': 'enable',
            'ippool': 'enable',
            'logtraffic': 'enable',
            'per_ip_shaper': 'test_value_9',
            'permit_any_host': 'enable',
            'policyid': '11',
            'schedule': 'test_value_12',
            'srcintf': 'test_value_13',
            'status': 'enable',
            'tcp_mss_receiver': '15',
            'tcp_mss_sender': '16',
            'traffic_shaper': 'test_value_17',
            'traffic_shaper_reverse': 'test_value_18',
            'uuid': 'test_value_19'
        },
        'vdom': 'root'
    }

    is_error, changed, response = fortios_firewall_policy64.fortios_firewall(
        input_data, fos_instance)

    expected_data = {
        'action': 'accept',
        'comments': 'test_value_4',
        'dstintf': 'test_value_5',
        'fixedport': 'enable',
        'ippool': 'enable',
        'logtraffic': 'enable',
        'per-ip-shaper': 'test_value_9',
        'permit-any-host': 'enable',
        'policyid': '11',
        'schedule': 'test_value_12',
        'srcintf': 'test_value_13',
        'status': 'enable',
        'tcp-mss-receiver': '15',
        'tcp-mss-sender': '16',
        'traffic-shaper': 'test_value_17',
        'traffic-shaper-reverse': 'test_value_18',
        'uuid': 'test_value_19'
    }

    set_method_mock.assert_called_with('firewall',
                                       'policy64',
                                       data=expected_data,
                                       vdom='root')
    schema_method_mock.assert_not_called()
    assert not is_error
    assert changed
    assert response['status'] == 'success'
    assert response['http_status'] == 200