| 1 |
import datetime |
| 2 |
import uuid |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
import globus_sdk |
| 7 |
from globus_sdk.testing import get_last_request, load_response |
| 8 |
|
| 9 |
ZERO_ID = uuid.UUID(int=0) |
| 10 |
|
| 11 |
|
| 12 |
def get_last_params(): |
| 13 |
return get_last_request().params |
| 14 |
|
| 15 |
|
| 16 |
@pytest.mark.parametrize( |
| 17 |
"paramname, paramvalue", |
| 18 |
[ |
| 19 |
("filter_task_id", ZERO_ID), |
| 20 |
("filter_task_id", "foo"), |
| 21 |
("filter_owner_id", ZERO_ID), |
| 22 |
("filter_owner_id", "foo"), |
| 23 |
("filter_endpoint", ZERO_ID), |
| 24 |
("filter_endpoint", "foo"), |
| 25 |
("filter_is_paused", True), |
| 26 |
("filter_is_paused", False), |
| 27 |
("filter_min_faults", 0), |
| 28 |
("filter_min_faults", 10), |
| 29 |
("filter_local_user", "foouser"), |
| 30 |
("filter_status", "ACTIVE"), |
| 31 |
("filter_completion_time", "2020-08-25T00:00:00,2021-08-25T16:05:28"), |
| 32 |
], |
| 33 |
) |
| 34 |
def test_strsafe_params(client, paramname, paramvalue): |
| 35 |
load_response(client.endpoint_manager_task_list) |
| 36 |
paramstr = str(paramvalue) |
| 37 |
client.endpoint_manager_task_list(**{paramname: paramvalue}) |
| 38 |
params = get_last_params() |
| 39 |
assert paramname in params |
| 40 |
assert params[paramname] == paramstr |
| 41 |
|
| 42 |
|
| 43 |
def test_filter_status_list(client): |
| 44 |
load_response(client.endpoint_manager_task_list) |
| 45 |
client.endpoint_manager_task_list(filter_status=["ACTIVE", "INACTIVE"]) |
| 46 |
params = get_last_params() |
| 47 |
assert "filter_status" in params |
| 48 |
assert params["filter_status"] == "ACTIVE,INACTIVE" |
| 49 |
|
| 50 |
|
| 51 |
def test_filter_task_id_list(client): |
| 52 |
load_response(client.endpoint_manager_task_list) |
| 53 |
# mixed list of str and UUID |
| 54 |
client.endpoint_manager_task_list(filter_task_id=["foo", ZERO_ID, "bar"]) |
| 55 |
params = get_last_params() |
| 56 |
assert "filter_task_id" in params |
| 57 |
assert params["filter_task_id"] == f"foo,{str(ZERO_ID)},bar" |
| 58 |
|
| 59 |
|
| 60 |
def test_filter_completion_time_datetime_tuple(client): |
| 61 |
load_response(client.endpoint_manager_task_list) |
| 62 |
|
| 63 |
dt1 = datetime.datetime.fromisoformat("2020-08-25T00:00:00") |
| 64 |
dt2 = datetime.datetime.fromisoformat("2021-08-25T16:05:28") |
| 65 |
|
| 66 |
client.endpoint_manager_task_list(filter_completion_time=(dt1, dt2)) |
| 67 |
params = get_last_params() |
| 68 |
assert "filter_completion_time" in params |
| 69 |
assert params["filter_completion_time"] == "2020-08-25T00:00:00,2021-08-25T16:05:28" |
| 70 |
|
| 71 |
# mixed tuples work, important for passing `""` |
| 72 |
client.endpoint_manager_task_list(filter_completion_time=(dt1, "")) |
| 73 |
params = get_last_params() |
| 74 |
assert "filter_completion_time" in params |
| 75 |
assert params["filter_completion_time"] == "2020-08-25T00:00:00," |
| 76 |
client.endpoint_manager_task_list(filter_completion_time=("", dt1)) |
| 77 |
params = get_last_params() |
| 78 |
assert "filter_completion_time" in params |
| 79 |
assert params["filter_completion_time"] == ",2020-08-25T00:00:00" |
| 80 |
|
| 81 |
|
| 82 |
@pytest.mark.parametrize("ep_use", ("source", "destination")) |
| 83 |
def test_filter_by_endpoint_use(client, ep_use): |
| 84 |
meta = load_response(client.endpoint_manager_task_list).metadata |
| 85 |
if ep_use == "source": |
| 86 |
ep_id = meta["source"] |
| 87 |
else: |
| 88 |
ep_id = meta["destination"] |
| 89 |
|
| 90 |
client.endpoint_manager_task_list(filter_endpoint=ep_id, filter_endpoint_use=ep_use) |
| 91 |
params = get_last_params() |
| 92 |
|
| 93 |
assert "filter_endpoint" in params |
| 94 |
assert params["filter_endpoint"] == str(ep_id) |
| 95 |
assert "filter_endpoint_use" in params |
| 96 |
assert params["filter_endpoint_use"] == ep_use |
| 97 |
|
| 98 |
|
| 99 |
@pytest.mark.parametrize("ep_use", ("source", "destination")) |
| 100 |
def test_usage_error_on_filter_endpoint_use_without_endpoint(client, ep_use): |
| 101 |
with pytest.raises( |
| 102 |
globus_sdk.GlobusSDKUsageError, |
| 103 |
match=( |
| 104 |
"`filter_endpoint_use` is only valid when `filter_endpoint` is " |
| 105 |
r"also supplied\." |
| 106 |
), |
| 107 |
): |
| 108 |
client.endpoint_manager_task_list(filter_endpoint_use=ep_use) |