| 1 |
import urllib.parse |
| 2 |
import uuid |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from globus_sdk import MISSING |
| 7 |
from globus_sdk.testing import get_last_request, load_response |
| 8 |
|
| 9 |
|
| 10 |
def test_list_runs_simple(flows_client): |
| 11 |
meta = load_response(flows_client.list_runs).metadata |
| 12 |
|
| 13 |
res = flows_client.list_runs() |
| 14 |
assert res.http_status == 200 |
| 15 |
|
| 16 |
# dict-like indexing |
| 17 |
assert meta["first_run_id"] == res["runs"][0]["run_id"] |
| 18 |
# list conversion (using __iter__) and indexing |
| 19 |
assert meta["first_run_id"] == list(res)[0]["run_id"] |
| 20 |
|
| 21 |
|
| 22 |
@pytest.mark.parametrize("by_pages", [True, False]) |
| 23 |
def test_list_runs_paginated(flows_client, by_pages): |
| 24 |
meta = load_response(flows_client.list_runs, case="paginated").metadata |
| 25 |
total_items = meta["total_items"] |
| 26 |
num_pages = meta["num_pages"] |
| 27 |
expect_markers = meta["expect_markers"] |
| 28 |
|
| 29 |
res = flows_client.paginated.list_runs() |
| 30 |
if by_pages: |
| 31 |
pages = list(res) |
| 32 |
assert len(pages) == num_pages |
| 33 |
for i, page in enumerate(pages): |
| 34 |
assert page["marker"] == expect_markers[i] |
| 35 |
if i < num_pages - 1: |
| 36 |
assert page["has_next_page"] is True |
| 37 |
else: |
| 38 |
assert page["has_next_page"] is False |
| 39 |
else: |
| 40 |
items = list(res.items()) |
| 41 |
assert len(items) == total_items |
| 42 |
|
| 43 |
|
| 44 |
@pytest.mark.parametrize("pass_as_uuids", [True, False]) |
| 45 |
def test_list_runs_filter_flow_id(flows_client, pass_as_uuids): |
| 46 |
meta = load_response(flows_client.list_runs, case="filter_flow_id").metadata |
| 47 |
# sanity check that the underlying test data hasn't changed too much |
| 48 |
assert len(meta["by_flow_id"]) == 2 |
| 49 |
flow_id_one, flow_id_two = tuple(meta["by_flow_id"].keys()) |
| 50 |
if pass_as_uuids: |
| 51 |
flow_id_one = uuid.UUID(flow_id_one) |
| 52 |
flow_id_two = uuid.UUID(flow_id_two) |
| 53 |
|
| 54 |
res_one = list(flows_client.list_runs(filter_flow_id=flow_id_one)) |
| 55 |
assert len(res_one) == meta["by_flow_id"][str(flow_id_one)]["num"] |
| 56 |
for run in res_one: |
| 57 |
assert run["flow_id"] == str(flow_id_one) |
| 58 |
|
| 59 |
res_two = list(flows_client.list_runs(filter_flow_id=flow_id_two)) |
| 60 |
assert len(res_two) == meta["by_flow_id"][str(flow_id_two)]["num"] |
| 61 |
for run in res_two: |
| 62 |
assert run["flow_id"] == str(flow_id_two) |
| 63 |
|
| 64 |
res_combined = list( |
| 65 |
flows_client.list_runs(filter_flow_id=[flow_id_one, flow_id_two]) |
| 66 |
) |
| 67 |
assert len(res_combined) == ( |
| 68 |
meta["by_flow_id"][str(flow_id_one)]["num"] |
| 69 |
+ meta["by_flow_id"][str(flow_id_two)]["num"] |
| 70 |
) |
| 71 |
for run in res_combined: |
| 72 |
assert run["flow_id"] in {str(flow_id_one), str(flow_id_two)} |
| 73 |
|
| 74 |
|
| 75 |
@pytest.mark.parametrize( |
| 76 |
"filter_roles, expected_filter_roles", |
| 77 |
[ |
| 78 |
# empty list/tuple, list/tuple with empty string, and None do not send the param |
| 79 |
([], None), |
| 80 |
((), None), |
| 81 |
([""], None), |
| 82 |
(("",), None), |
| 83 |
(MISSING, None), |
| 84 |
# single role as string |
| 85 |
("foo", ["foo"]), |
| 86 |
# single role as list/tuple |
| 87 |
(["foo"], ["foo"]), |
| 88 |
(("foo",), ["foo"]), |
| 89 |
# multiple roles as comma-separated string |
| 90 |
("foo,bar", ["foo,bar"]), |
| 91 |
# multiple roles as list/tuple |
| 92 |
(["foo", "bar"], ["foo,bar"]), |
| 93 |
(("foo", "bar"), ["foo,bar"]), |
| 94 |
], |
| 95 |
) |
| 96 |
def test_list_runs_filter_roles(flows_client, filter_roles, expected_filter_roles): |
| 97 |
load_response(flows_client.list_runs).metadata |
| 98 |
res = flows_client.list_runs(filter_roles=filter_roles) |
| 99 |
assert res.http_status == 200 |
| 100 |
|
| 101 |
req = get_last_request() |
| 102 |
assert req.body is None |
| 103 |
parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query) |
| 104 |
|
| 105 |
if expected_filter_roles: |
| 106 |
assert parsed_qs["filter_roles"] == expected_filter_roles |
| 107 |
else: |
| 108 |
assert "filter_roles" not in parsed_qs |