Exemplo n.º 1
0
def test_firewall_ippool_deletion_fails(mocker):
    schema_method_mock = mocker.patch(
        'ansible_collections.fortinet.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.fortinet.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.delete',
        return_value=delete_method_result)

    input_data = {
        'username': '******',
        'state': 'absent',
        'firewall_ippool': {
            'arp_intf': 'test_value_3',
            'arp_reply': 'disable',
            'associated_interface': 'test_value_5',
            'block_size': '6',
            'comments': 'test_value_7',
            'endip': 'test_value_8',
            'name': 'default_name_9',
            'num_blocks_per_user': '******',
            'pba_timeout': '11',
            'permit_any_host': 'disable',
            'source_endip': 'test_value_13',
            'source_startip': 'test_value_14',
            'startip': 'test_value_15',
            'type': 'overload'
        },
        'vdom': 'root'
    }

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

    delete_method_mock.assert_called_with('firewall',
                                          'ippool',
                                          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
Exemplo n.º 2
0
def test_firewall_ippool_creation(mocker):
    schema_method_mock = mocker.patch(
        'ansible_collections.fortinet.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.fortinet.fortios.plugins.module_utils.network.fortios.fortios.FortiOSHandler.set',
        return_value=set_method_result)

    input_data = {
        'username': '******',
        'state': 'present',
        'firewall_ippool': {
            'arp_intf': 'test_value_3',
            'arp_reply': 'disable',
            'associated_interface': 'test_value_5',
            'block_size': '6',
            'comments': 'test_value_7',
            'endip': 'test_value_8',
            'name': 'default_name_9',
            'num_blocks_per_user': '******',
            'pba_timeout': '11',
            'permit_any_host': 'disable',
            'source_endip': 'test_value_13',
            'source_startip': 'test_value_14',
            'startip': 'test_value_15',
            'type': 'overload'
        },
        'vdom': 'root'
    }

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

    expected_data = {
        'arp-intf': 'test_value_3',
        'arp-reply': 'disable',
        'associated-interface': 'test_value_5',
        'block-size': '6',
        'comments': 'test_value_7',
        'endip': 'test_value_8',
        'name': 'default_name_9',
        'num-blocks-per-user': '******',
        'pba-timeout': '11',
        'permit-any-host': 'disable',
        'source-endip': 'test_value_13',
        'source-startip': 'test_value_14',
        'startip': 'test_value_15',
        'type': 'overload'
    }

    set_method_mock.assert_called_with('firewall',
                                       'ippool',
                                       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