예제 #1
0
def test_firewall_shaper_traffic_shaper_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_shaper_traffic_shaper': {
            'bandwidth_unit': 'kbps',
            'diffserv': 'enable',
            'diffservcode': 'test_value_5',
            'guaranteed_bandwidth': '6',
            'maximum_bandwidth': '7',
            'name': 'default_name_8',
            'per_policy': 'disable',
            'priority': 'low'
        },
        'vdom': 'root'}

    is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)

    delete_method_mock.assert_called_with('firewall.shaper', 'traffic-shaper', 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_shaper_traffic_shaper_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_shaper_traffic_shaper': {
            'random_attribute_not_valid': 'tag',
            'bandwidth_unit': 'kbps',
            'diffserv': 'enable',
            'diffservcode': 'test_value_5',
            'guaranteed_bandwidth': '6',
            'maximum_bandwidth': '7',
            'name': 'default_name_8',
            'per_policy': 'disable',
            'priority': 'low'
        },
        'vdom': 'root'}

    is_error, changed, response = fortios_firewall_shaper_traffic_shaper.fortios_firewall_shaper(input_data, fos_instance)

    expected_data = {
        'bandwidth-unit': 'kbps',
        'diffserv': 'enable',
        'diffservcode': 'test_value_5',
        'guaranteed-bandwidth': '6',
        'maximum-bandwidth': '7',
        'name': 'default_name_8',
                'per-policy': 'disable',
                'priority': 'low'
    }

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