-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'orderby' to TransferClient.task_list #1011
Merged
+173
−87
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
263964a
Add 'orderby' as to 'TransferClient.task_list'
sirosen 1f6bffe
Move task_list tests to new paradigm
sirosen aeef3bc
Add a test for the 'orderby' task_list param
sirosen d3f493d
Add example for TransferClient.task_list orderby
sirosen da69de5
Update src/globus_sdk/services/transfer/client.py
sirosen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Added | ||
~~~~~ | ||
|
||
- The ``TransferClient.task_list`` method now supports ``orderby`` as a | ||
parameter. (:pr:`NUMBER`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import uuid | ||
|
||
from globus_sdk._testing.models import RegisteredResponse, ResponseSet | ||
|
||
source_id = str(uuid.uuid4()) | ||
destination_id = str(uuid.uuid4()) | ||
owner_id = str(uuid.uuid4()) | ||
task_id = str(uuid.uuid4()) | ||
|
||
TASK_LIST_DOC = { | ||
"DATA": [ | ||
{ | ||
"bytes_checksummed": 0, | ||
"bytes_transferred": 4, | ||
"canceled_by_admin": None, | ||
"canceled_by_admin_message": None, | ||
"command": "API 0.10", | ||
"completion_time": "2021-09-02T18:04:49+00:00", | ||
"deadline": "2021-09-03T18:04:47+00:00", | ||
"delete_destination_extra": False, | ||
"destination_endpoint": "mydest", | ||
"destination_endpoint_display_name": "Destination Endpoint", | ||
"destination_endpoint_id": destination_id, | ||
"directories": 0, | ||
"effective_bytes_per_second": 3, | ||
"encrypt_data": False, | ||
"fail_on_quota_errors": False, | ||
"fatal_error": None, | ||
"faults": 0, | ||
"files": 1, | ||
"files_skipped": 0, | ||
"files_transferred": 1, | ||
"filter_rules": None, | ||
"history_deleted": False, | ||
"is_ok": None, | ||
"is_paused": False, | ||
"label": None, | ||
"nice_status": None, | ||
"nice_status_details": None, | ||
"nice_status_expires_in": None, | ||
"nice_status_short_description": None, | ||
"owner_id": owner_id, | ||
"preserve_timestamp": False, | ||
"recursive_symlinks": "ignore", | ||
"request_time": "2021-09-02T18:04:47+00:00", | ||
"skip_source_errors": False, | ||
"source_endpoint": "mysrc", | ||
"source_endpoint_display_name": "Source Endpoint", | ||
"source_endpoint_id": source_id, | ||
"status": "SUCCEEDED", | ||
"subtasks_canceled": 0, | ||
"subtasks_expired": 0, | ||
"subtasks_failed": 0, | ||
"subtasks_pending": 0, | ||
"subtasks_retrying": 0, | ||
"subtasks_skipped_errors": 0, | ||
"subtasks_succeeded": 2, | ||
"subtasks_total": 2, | ||
"symlinks": 0, | ||
"sync_level": None, | ||
"task_id": task_id, | ||
"type": "TRANSFER", | ||
"username": "u_XrtivK6z9w2MZwr65os6nZX0wv", | ||
"verify_checksum": True, | ||
} | ||
], | ||
"DATA_TYPE": "task_list", | ||
"length": 1, | ||
"limit": 1000, | ||
"offset": 0, | ||
"total": 1, | ||
} | ||
|
||
|
||
RESPONSES = ResponseSet( | ||
metadata={ | ||
"tasks": [ | ||
{ | ||
"source_id": source_id, | ||
"destination_id": destination_id, | ||
"owner_id": owner_id, | ||
"task_id": task_id, | ||
} | ||
], | ||
}, | ||
default=RegisteredResponse( | ||
service="transfer", | ||
path="/task_list", | ||
json=TASK_LIST_DOC, | ||
), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 0 additions & 63 deletions
63
tests/functional/services/transfer/fixture_data/task_list.json
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import urllib.parse | ||
|
||
import pytest | ||
|
||
from globus_sdk._testing import get_last_request, load_response | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"client_kwargs, qs", | ||
[ | ||
({}, {}), | ||
({"query_params": {"foo": "bar"}}, {"foo": "bar"}), | ||
({"filter": "foo"}, {"filter": "foo"}), | ||
({"limit": 10, "offset": 100}, {"limit": "10", "offset": "100"}), | ||
({"limit": 10, "query_params": {"limit": 100}}, {"limit": "10"}), | ||
({"filter": "foo:bar:baz"}, {"filter": "foo:bar:baz"}), | ||
({"filter": {"foo": "bar", "bar": "baz"}}, {"filter": "foo:bar/bar:baz"}), | ||
({"filter": {"foo": ["bar", "baz"]}}, {"filter": "foo:bar,baz"}), | ||
], | ||
) | ||
def test_task_list(client, client_kwargs, qs): | ||
load_response(client.task_list) | ||
client.task_list(**client_kwargs) | ||
|
||
req = get_last_request() | ||
parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query) | ||
# parsed_qs will have each value as a list (because query-params are a multidict) | ||
# so transform the test data to match before comparison | ||
assert parsed_qs == {k: [v] for k, v in qs.items()} | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"orderby_value, expected_orderby_param", | ||
[ | ||
("foo", "foo"), | ||
(["foo"], "foo"), | ||
("foo,bar", "foo,bar"), | ||
("foo ASC,bar", "foo ASC,bar"), | ||
(["foo ASC", "bar"], "foo ASC,bar"), | ||
(["foo ASC", "bar DESC"], "foo ASC,bar DESC"), | ||
], | ||
) | ||
def test_task_list_orderby_parameter(client, orderby_value, expected_orderby_param): | ||
load_response(client.task_list) | ||
client.task_list(orderby=orderby_value) | ||
|
||
req = get_last_request() | ||
parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query) | ||
assert "orderby" in parsed_qs | ||
assert len(parsed_qs["orderby"]) == 1 | ||
orderby_param = parsed_qs["orderby"][0] | ||
assert orderby_param == expected_orderby_param |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't looked up the exact syntax, but the else branch here joins on a comma instead of a space which is specified in the
:param
doc aboveThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is right -- but if it's wrong we probably have to fix other method implementations, since I 100% copied this from elsewhere in the module.
I think Transfer accepts multiple ordering criteria comma-separated, like
created ASC,terminated DESC
. I'll double-check the docs and run a live test or two to see if this is right.If it is though, it maybe needs slightly more docstring, since I think this is a potential point of confusion with
["created ASC", "terminated DESC"]
vs["created", "ASC"]
. 😵💫There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just live-blogging my process here a little bit, I'm reaching for
globus api
to check this really easily.This fails (good!):
and this works:
So the space is correct. And then we get to some other things which work, like
So I'm pretty sure I have the usage here correct ( 😌 ).
But now I think this accepting a list is potentially confusing, so I think this needs enhanced doc (i.e. at least one complex example).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm with Jake that the docstring can be updated to help clarify this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added an example usage because I'm not sure what the full scope of the documentation here should be. I don't want to overwhelm a reader, but I want to point them in the right direction.
It's in a fresh commit; let me know if it needs further refinement!