| 1 |
import dataclasses |
| 2 |
import urllib.parse |
| 3 |
|
| 4 |
import pytest |
| 5 |
|
| 6 |
from globus_sdk._missing import MISSING |
| 7 |
from globus_sdk.testing import get_last_request, load_response |
| 8 |
|
| 9 |
|
| 10 |
def test_search_index_list(client): |
| 11 |
meta = load_response(client.index_list).metadata |
| 12 |
index_ids = meta["index_ids"] |
| 13 |
|
| 14 |
res = client.index_list() |
| 15 |
assert res.http_status == 200 |
| 16 |
|
| 17 |
index_list = res["index_list"] |
| 18 |
assert isinstance(index_list, list) |
| 19 |
assert len(index_list) == len(index_ids) |
| 20 |
assert [i["id"] for i in index_list] == index_ids |
| 21 |
|
| 22 |
|
| 23 |
def test_search_index_list_is_iterable(client): |
| 24 |
meta = load_response(client.index_list).metadata |
| 25 |
index_ids = meta["index_ids"] |
| 26 |
|
| 27 |
res = client.index_list() |
| 28 |
assert res.http_status == 200 |
| 29 |
|
| 30 |
index_list = list(res) |
| 31 |
assert len(index_list) == len(index_ids) |
| 32 |
assert [i["id"] for i in index_list] == index_ids |
| 33 |
|
| 34 |
|
| 35 |
_OMIT = object() |
| 36 |
|
| 37 |
|
| 38 |
@dataclasses.dataclass |
| 39 |
class FilterRoleParam: |
| 40 |
name: str |
| 41 |
value: object |
| 42 |
expect_parsed_param: object = None |
| 43 |
|
| 44 |
@property |
| 45 |
def missing(self) -> bool: |
| 46 |
return self.value in (_OMIT, MISSING) |
| 47 |
|
| 48 |
@property |
| 49 |
def call_kwargs(self) -> dict[str, object]: |
| 50 |
return {} if self.value is _OMIT else {"filter_roles": self.value} |
| 51 |
|
| 52 |
def __str__(self) -> str: |
| 53 |
return self.name |
| 54 |
|
| 55 |
|
| 56 |
@pytest.mark.parametrize( |
| 57 |
"filter_param", |
| 58 |
[ |
| 59 |
FilterRoleParam("omitted", _OMIT), |
| 60 |
FilterRoleParam("missing", MISSING), |
| 61 |
FilterRoleParam("ownerstr", "owner", ["owner"]), |
| 62 |
FilterRoleParam("adminstr", "admin", ["admin"]), |
| 63 |
FilterRoleParam("writerstr", "writer", ["writer"]), |
| 64 |
FilterRoleParam("tuple", ("owner", "admin"), ["owner,admin"]), |
| 65 |
FilterRoleParam("list", ["admin", "writer"], ["admin,writer"]), |
| 66 |
FilterRoleParam("duplicates", ("admin", "admin"), ["admin,admin"]), |
| 67 |
# this isn't a real role, but it should be passed through as though it were |
| 68 |
# -- this value can be a typing time error but never a runtime error |
| 69 |
FilterRoleParam("unknown_str", "ambassador", ["ambassador"]), |
| 70 |
], |
| 71 |
ids=str, |
| 72 |
) |
| 73 |
def test_search_index_list_encodes_filter_roles_as_expected(client, filter_param): |
| 74 |
load_response(client.index_list).metadata |
| 75 |
res = client.index_list(**filter_param.call_kwargs) |
| 76 |
assert res.http_status == 200 |
| 77 |
|
| 78 |
req = get_last_request() |
| 79 |
parsed_qs = urllib.parse.parse_qs(urllib.parse.urlparse(req.url).query) |
| 80 |
if filter_param.missing: |
| 81 |
assert "filter_roles" not in parsed_qs |
| 82 |
else: |
| 83 |
assert parsed_qs["filter_roles"] == filter_param.expect_parsed_param |