def METHOD_NAME(client, librarian_martigny, patron_martigny):
    """Test users search REST API."""
    l_martigny = librarian_martigny
    librarian_martigny = librarian_martigny.dumps()
    p_martigny = patron_martigny
    patron_martigny = patron_martigny.dumps()
    res = client.get(
        url_for(
            'api_users.users_list',
            q=''
        )
    )
    assert res.status_code == 401
    login_user_via_session(client, l_martigny.user)
    # empty query => no result
    res = client.get(
        url_for(
            'api_users.users_list',
            q=''
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'] == []
    assert hits['hits']['total']['value'] == 0
    # all by username
    res = client.get(
        url_for(
            'api_users.users_list',
            q=patron_martigny['username']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']
    assert hits['hits']['total']['value'] == 1
    # all by email
    res = client.get(
        url_for(
            'api_users.users_list',
            q=patron_martigny['email']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']
    assert hits['hits']['total']['value'] == 1
    # by username
    res = client.get(
        url_for(
            'api_users.users_list',
            q='username:' + patron_martigny['username']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']
    assert hits['hits']['total']['value'] == 1
    # by email
    res = client.get(
        url_for(
            'api_users.users_list',
            q='email:' + patron_martigny['email']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']
    assert hits['hits']['total']['value'] == 1
    # by uppercase email
    res = client.get(
        url_for(
            'api_users.users_list',
            q='email:' + patron_martigny['email'].upper()
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']
    assert hits['hits']['total']['value'] == 1
    # Login with patron role
    login_user_via_session(client, p_martigny.user)
    res = client.get(
        url_for(
            'api_users.users_list',
            q=patron_martigny['username']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert 'metadata' not in hits['hits']['hits'][0]
    assert hits['hits']['hits'][0]['id'] == patron_martigny['user_id']
    res = client.get(
        url_for(
            'api_users.users_item',
            id=p_martigny.user.id
        )
    )
    assert res.status_code == 200
    record = get_json(res)
    assert patron_martigny['username'] == record.get('metadata', [])\
        .get('username')
    # Login with librarian role
    login_user_via_session(client, l_martigny.user)
    res = client.get(
        url_for(
            'api_users.users_list',
            q=patron_martigny['username']
        )
    )
    assert res.status_code == 200
    hits = get_json(res)
    assert 'metadata' in hits['hits']['hits'][0]
    assert hits['hits']['hits'][0]['metadata']['username'] == \
        patron_martigny['username']