def test_user_local_deletion_fails(mocker):
    schema_method_mock = mocker.patch(
        'ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')

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

    input_data = {
        'username': '******',
        'state': 'absent',
        'user_local': {
            'auth_concurrent_override': 'enable',
            'auth_concurrent_value': '4',
            'authtimeout': '5',
            'email_to': 'test_value_6',
            'fortitoken': 'test_value_7',
            'id': '8',
            'ldap_server': 'test_value_9',
            'name': 'default_name_10',
            'passwd': 'test_value_11',
            'passwd_policy': 'test_value_12',
            'passwd_time': 'test_value_13',
            'ppk_identity': 'test_value_14',
            'ppk_secret': 'test_value_15',
            'radius_server': 'test_value_16',
            'sms_custom_server': 'test_value_17',
            'sms_phone': 'test_value_18',
            'sms_server': 'fortiguard',
            'status': 'enable',
            'tacacs+_server': 'test_value_21',
            'two_factor': 'disable',
            'type': 'password',
            'workstation': 'test_value_24'
        },
        'vdom': 'root'
    }

    is_error, changed, response = fortios_user_local.fortios_user(
        input_data, fos_instance)

    delete_method_mock.assert_called_with('user',
                                          'local',
                                          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
def test_user_local_filter_foreign_attributes(mocker):
    schema_method_mock = mocker.patch(
        'ansible.module_utils.network.fortios.fortios.FortiOSHandler.schema')

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

    input_data = {
        'username': '******',
        'state': 'present',
        'user_local': {
            'random_attribute_not_valid': 'tag',
            'auth_concurrent_override': 'enable',
            'auth_concurrent_value': '4',
            'authtimeout': '5',
            'email_to': 'test_value_6',
            'fortitoken': 'test_value_7',
            'id': '8',
            'ldap_server': 'test_value_9',
            'name': 'default_name_10',
            'passwd': 'test_value_11',
            'passwd_policy': 'test_value_12',
            'passwd_time': 'test_value_13',
            'ppk_identity': 'test_value_14',
            'ppk_secret': 'test_value_15',
            'radius_server': 'test_value_16',
            'sms_custom_server': 'test_value_17',
            'sms_phone': 'test_value_18',
            'sms_server': 'fortiguard',
            'status': 'enable',
            'tacacs+_server': 'test_value_21',
            'two_factor': 'disable',
            'type': 'password',
            'workstation': 'test_value_24'
        },
        'vdom': 'root'
    }

    is_error, changed, response = fortios_user_local.fortios_user(
        input_data, fos_instance)

    expected_data = {
        'auth-concurrent-override': 'enable',
        'auth-concurrent-value': '4',
        'authtimeout': '5',
        'email-to': 'test_value_6',
        'fortitoken': 'test_value_7',
        'id': '8',
        'ldap-server': 'test_value_9',
        'name': 'default_name_10',
        'passwd': 'test_value_11',
        'passwd-policy': 'test_value_12',
        'passwd-time': 'test_value_13',
        'ppk-identity': 'test_value_14',
        'ppk-secret': 'test_value_15',
        'radius-server': 'test_value_16',
        'sms-custom-server': 'test_value_17',
        'sms-phone': 'test_value_18',
        'sms-server': 'fortiguard',
        'status': 'enable',
        'tacacs+-server': 'test_value_21',
        'two-factor': 'disable',
        'type': 'password',
        'workstation': 'test_value_24'
    }

    set_method_mock.assert_called_with('user',
                                       'local',
                                       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