def METHOD_NAME(client, librarian_martigny,
                                patron_martigny, loc_public_martigny,
                                item_type_standard_martigny,
                                item3_lib_martigny, json_header,
                                item4_lib_martigny,
                                circulation_policies):
    """Test sort of checkout loans."""
    login_user_via_session(client, librarian_martigny.user)
    res, _ = postdata(
        client,
        'api_item.checkout',
        dict(
            item_pid=item3_lib_martigny.pid,
            patron_pid=patron_martigny.pid,
            transaction_user_pid=librarian_martigny.pid,
            transaction_location_pid=loc_public_martigny.pid
        ),
    )
    assert res.status_code == 200
    res, _ = postdata(
        client,
        'api_item.checkout',
        dict(
            item_pid=item4_lib_martigny.pid,
            patron_pid=patron_martigny.pid,
            transaction_user_pid=librarian_martigny.pid,
            transaction_location_pid=loc_public_martigny.pid
        ),
    )
    assert res.status_code == 200
    # sort by transaction_date asc
    res = client.get(
        url_for(
            'api_item.loans', patron_pid=patron_martigny.pid,
            sort='_created'))
    assert res.status_code == 200
    data = get_json(res)
    items = data['hits']['hits']
    assert items[0]['item']['pid'] == item3_lib_martigny.pid
    assert items[1]['item']['pid'] == item4_lib_martigny.pid
    # sort by transaction_date desc
    res = client.get(
        url_for(
            'api_item.loans', patron_pid=patron_martigny.pid,
            sort='-transaction_date'))
    assert res.status_code == 200
    data = get_json(res)
    items = data['hits']['hits']
    assert items[0]['item']['pid'] == item4_lib_martigny.pid
    assert items[1]['item']['pid'] == item3_lib_martigny.pid
    # sort by invalid field
    res = client.get(
        url_for(
            'api_item.loans', patron_pid=patron_martigny.pid,
            sort='does not exist'))
    assert res.status_code == 500
    data = get_json(res)
    assert 'RequestError(400' in data['status']