Debian Codegraph @

tests/functional/services/gcs/test_collections.py

raw
1 from globus_sdk import GuestCollectionDocument, MappedCollectionDocument
2 from tests.common import register_api_route_fixture_file
3
4
5 def test_get_collection(client):
6 register_api_route_fixture_file(
7 "gcs", "/collections/COLLECTION_ID", "get_collection/normal.json"
8 )
9 res = client.get_collection("COLLECTION_ID")
10 assert res["DATA_TYPE"] == "collection#1.0.0"
11 assert res.full_data["DATA_TYPE"] == "result#1.0.0"
12 assert "detail" in res.full_data
13 assert "data" in res.full_data
14 assert res.full_data["detail"] == "success"
15 assert "detail" not in res.data
16 assert res["display_name"] == "Happy Fun Collection Name"
17
18
19 def test_get_collection_flat(client):
20 register_api_route_fixture_file(
21 "gcs", "/collections/COLLECTION_ID", "get_collection/unexpectedly_flat.json"
22 )
23 res = client.get_collection("COLLECTION_ID")
24 assert res["DATA_TYPE"] == "collection#1.0.0"
25 assert res.full_data["DATA_TYPE"] == "collection#1.0.0"
26 assert "detail" not in res.full_data
27 assert "data" not in res.full_data
28 assert res["display_name"] == "Happy Fun Collection Name"
29
30
31 def test_get_collection_bad_version(client):
32 register_api_route_fixture_file(
33 "gcs", "/collections/COLLECTION_ID", "get_collection/bad_version.json"
34 )
35 res = client.get_collection("COLLECTION_ID")
36 assert res["DATA_TYPE"] == "result#1.0.0"
37 assert res.full_data["DATA_TYPE"] == "result#1.0.0"
38 assert "detail" in res.full_data
39 assert "data" in res.full_data
40 assert res.full_data["detail"] == "success"
41 assert "detail" in res.data
42 assert "foo" not in res.data
43 for x in res.full_data["data"]:
44 assert "foo" in x
45
46
47 def test_get_collection_includes_sideloaded_data(client):
48 register_api_route_fixture_file(
49 "gcs", "/collections/COLLECTION_ID", "get_collection/includes_other.json"
50 )
51 res = client.get_collection("COLLECTION_ID")
52 assert res["DATA_TYPE"] == "collection#1.0.0"
53 assert res.full_data["DATA_TYPE"] == "result#1.0.0"
54 assert "detail" in res.full_data
55 assert "data" in res.full_data
56 assert res.full_data["detail"] == "success"
57 assert "detail" not in res.data
58 assert res["display_name"] == "Happy Fun Collection Name"
59
60
61 def test_get_collection_invalid_datatype_type(client):
62 register_api_route_fixture_file(
63 "gcs", "/collections/COLLECTION_ID", "get_collection/invalid_datatype_type.json"
64 )
65 res = client.get_collection("COLLECTION_ID")
66 assert res["DATA_TYPE"] == "result#1.0.0"
67 assert res.full_data["DATA_TYPE"] == "result#1.0.0"
68 assert "detail" in res.full_data
69 assert "detail" in res.data
70 assert "data" in res.full_data
71 assert res.full_data["detail"] == "success"
72
73
74 def test_delete_collection(client):
75 register_api_route_fixture_file(
76 "gcs", "/collections/COLLECTION_ID", "empty_success.json", method="DELETE"
77 )
78 res = client.delete_collection("COLLECTION_ID")
79 assert res["DATA_TYPE"] == "result#1.0.0"
80 assert "detail" in res.data
81 assert res.data["detail"] == "success"
82
83
84 def test_create_mapped_collection(client):
85 register_api_route_fixture_file(
86 "gcs", "/collections", "create_collection.json", method="POST"
87 )
88 collection = MappedCollectionDocument(
89 domain_name="i-f3c83.123.globus.org",
90 display_name="Project Foo Research Data",
91 identity_id="c8b7ab5c-595c-43c9-8e43-9e8a3debfe4c",
92 storage_gateway_id="fc1f3ba0-1fa4-42b2-8bb3-53983774fa5f",
93 collection_base_path="/",
94 default_directory="/projects",
95 public=True,
96 force_encryption=False,
97 disable_verify=False,
98 organization="University of Example",
99 department="Data Science",
100 keywords=["Project Foo", "Data Intensive Science"],
101 description='Information related to the "Foo" project.',
102 contact_email="[email protected]",
103 contact_info="+1 (555) 555-1234",
104 info_link="https://project-foo.example.edu/info",
105 policies={"DATA_TYPE": "blackpearl_collection_policies#1.0.0"},
106 allow_guest_collections=True,
107 sharing_restrict_paths={
108 "DATA_TYPE": "path_restrictions#1.0.0",
109 "read": ["/public"],
110 "read_write": ["/home", "/projects"],
111 "none": ["/private"],
112 },
113 )
114 res = client.create_collection(collection)
115 assert res["DATA_TYPE"] == "collection#1.0.0"
116 assert res["display_name"] == "Project Foo Research Data"
117
118
119 def test_update_guest_collection(client):
120 register_api_route_fixture_file(
121 "gcs", "/collections/COLLECTION_ID", "update_collection.json", method="PATCH"
122 )
123 collection = GuestCollectionDocument(display_name="Project Foo Research Data")
124 res = client.update_collection("COLLECTION_ID", collection)
125 assert res["DATA_TYPE"] == "collection#1.0.0"
126 assert res["display_name"] == "Project Foo Research Data"