File: test_get_collection_list.py

package info (click to toggle)
python-globus-sdk 4.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,144 kB
  • sloc: python: 35,242; sh: 37; makefile: 35
file content (74 lines) | stat: -rw-r--r-- 2,567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import pytest

from globus_sdk import MISSING, GCSAPIError
from globus_sdk.testing import get_last_request, load_response


def test_get_collection_list(client):
    meta = load_response(client.get_collection_list).metadata
    res = client.get_collection_list()

    # check the results against response metadata to ensure integrity and that
    # response parsing works
    assert len(list(res)) == len(meta["collection_ids"])
    assert res["DATA_TYPE"] == "result#1.0.0"
    for index, item in enumerate(res):
        assert item["DATA_TYPE"] == "collection#1.0.0"
        assert item["id"] == meta["collection_ids"][index]
        assert item["storage_gateway_id"] == meta["gateway_ids"][index]
        assert item["display_name"] == meta["display_names"][index]


@pytest.mark.parametrize(
    "include_param, expected",
    (
        (MISSING, None),
        ("foo", "foo"),
        ("foo,bar", "foo,bar"),
        (("foo", "bar"), "foo,bar"),
    ),
)
def test_get_collection_list_include_param(client, include_param, expected):
    load_response(client.get_collection_list)
    client.get_collection_list(include=include_param)
    req = get_last_request()
    if include_param is not MISSING:
        assert "include" in req.params
        assert req.params["include"] == expected
    else:
        assert "include" not in req.params


def test_get_collection_list_mapped_collection_id_param(client):
    load_response(client.get_collection_list)
    client.get_collection_list(mapped_collection_id="MAPPED_COLLECTION")
    assert get_last_request().params.get("mapped_collection_id") == "MAPPED_COLLECTION"


@pytest.mark.parametrize(
    "filter_param, expected",
    (
        (["mapped_collections", "created_by_me"], "mapped_collections,created_by_me"),
        ("created_by_me", "created_by_me"),
    ),
)
def test_get_collection_list_filter_param(client, filter_param, expected):
    load_response(client.get_collection_list)
    client.get_collection_list(filter=filter_param)
    assert get_last_request().params.get("filter") == expected


def test_error_parsing_forbidden(client):
    """
    This test is more focused on error parsing than it is on the actual collection list
    call.
    """
    load_response(client.get_collection_list, case="forbidden")
    with pytest.raises(GCSAPIError) as excinfo:
        client.get_collection_list()

    err = excinfo.value
    assert err.detail is None
    assert err.detail_data_type is None
    assert err.message.startswith("Could not list collections")
    assert err.code == "permission_denied"