File: test_roles.py

package info (click to toggle)
python-globus-sdk 4.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,172 kB
  • sloc: python: 35,227; sh: 44; makefile: 35
file content (106 lines) | stat: -rw-r--r-- 3,298 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import json

from globus_sdk import GCSRoleDocument
from globus_sdk.testing import get_last_request
from tests.common import register_api_route_fixture_file


def test_get_role_list(client):
    register_api_route_fixture_file("gcs", "/roles", "role_list.json")
    res = client.get_role_list()

    assert len(list(res)) == 2
    # sanity check some fields
    assert res["DATA_TYPE"] == "result#1.0.0"
    for item in res:
        assert item["DATA_TYPE"] == "role#1.0.0"
        assert "id" in item
        assert item["id"] in ("{role_id_1}", "{role_id_2}")
        assert "principal" in item
        assert "role" in item


def test_get_role_list_params(client):
    """
    confirms include, collection_id, and arbitrary query_params arguments
    to get_role_list are assembled correctly
    """
    register_api_route_fixture_file("gcs", "/roles", "role_list.json")

    # no args
    res = client.get_role_list()
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {}

    # collection_id
    res = client.get_role_list(collection_id="{collection_id_1}")
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"collection_id": "{collection_id_1}"}

    # include
    res = client.get_role_list(include="all_roles")
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"include": "all_roles"}

    # query_params
    res = client.get_role_list(query_params={"foo": "bar"})
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {"foo": "bar"}

    # everything together
    res = client.get_role_list(
        collection_id="{collection_id_1}",
        include="all_roles",
        query_params={"foo": "bar"},
    )
    assert res["code"] == "success"
    params = get_last_request().params
    assert params == {
        "collection_id": "{collection_id_1}",
        "include": "all_roles",
        "foo": "bar",
    }


def test_create_role(client):
    register_api_route_fixture_file(
        "gcs", "/roles", "role_document.json", method="POST"
    )

    data = GCSRoleDocument(
        collection="{collection_id_1}",
        principal="urn:globus:auth:identity:{user_id_1}",
        role="owner",
    )
    res = client.create_role(data)
    assert res["id"] == "{role_id_1}"

    json_body = json.loads(get_last_request().body)

    assert json_body["collection"] in (None, "{collection_id_1}")
    assert json_body["principal"] == "urn:globus:auth:identity:{user_id_1}"
    assert json_body["role"] in ("owner", "administrator")


def test_get_role(client):
    register_api_route_fixture_file("gcs", "/roles/ROLE_ID", "role_document.json")
    res = client.get_role("ROLE_ID")
    assert res["DATA_TYPE"] == "role#1.0.0"
    assert res["id"] == "{role_id_1}"
    assert res["collection"] is None
    assert res["principal"] == "urn:globus:auth:identity:{user_id_1}"
    assert res["role"] == "owner"


def test_delete_role(client):
    register_api_route_fixture_file(
        "gcs", "/roles/ROLE_ID", "empty_success.json", method="DELETE"
    )
    res = client.delete_role("ROLE_ID")
    assert res["DATA_TYPE"] == "result#1.0.0"
    assert "detail" in res.data
    assert res.data["detail"] == "success"