1010
1111dpath = pathlib .Path (__file__ ).parent / "data" / "calibration_beads_47.rtdc"
1212
13+ HAS_FIGSHARE_ACCESS = common .get_test_defaults ()["user" ] == "dcoraid"
1314
15+
16+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
17+ reason = "No access to figshare-import circle" )
1418def test_get_circles ():
1519 api = common .get_api ()
1620 db = db_api .APIInterrogator (api = api )
1721 circles = db .get_circles ()
18- assert common .CIRCLE in circles
22+ defaults = common .get_test_defaults ()
23+ assert defaults ["circle" ] in circles
1924 # requires that the "dcoraid" user is in the figshare-import circle
2025 assert "figshare-import" in circles
2126
2227
28+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
29+ reason = "No access to figshare-import circle" )
2330def test_get_collections ():
2431 api = common .get_api ()
2532 db = db_api .APIInterrogator (api = api )
2633 collections = db .get_collections ()
27- assert common .COLLECTION in collections
28- # requires that the "dcoraid" user is in the figshare-collection collection
34+ defaults = common .get_test_defaults ()
35+ assert defaults ["collection" ] in collections
36+ # requires that the "dcoraid" user is in figshare-collection collection
2937 assert "figshare-collection" in collections
3038
3139
@@ -40,80 +48,84 @@ def test_public_api_interrogator():
4048 """This test uses the figshare datasets on SERVER"""
4149 api = common .get_api ()
4250 db = db_api .APIInterrogator (api = api )
43- assert common .CIRCLE in db .get_circles ()
44- assert common .COLLECTION in db .get_collections ()
45- assert common .USER in db .get_users ()
51+ defaults = common .get_test_defaults ()
52+ assert defaults ["circle" ] in db .get_circles ()
53+ assert defaults ["collection" ] in db .get_collections ()
54+ assert defaults ["user" ] in db .get_users ()
4655
4756
4857def test_user_data ():
4958 """Test the user information"""
5059 api = common .get_api ()
5160 db = db_api .APIInterrogator (api = api )
5261 data = db .user_data
53- assert data ["fullname" ] == common .USER_NAME , "fullname not correct"
62+ defaults = common .get_test_defaults ()
63+ assert data ["fullname" ] == defaults ["user_name" ], "fullname not correct"
5464
5565
5666def test_search_dataset_basic ():
5767 api = common .get_api ()
5868 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
69+ defaults = common .get_test_defaults ()
5970 # Create a test dataset
60- dataset_create ({"title" : "{} {}" .format (common . TITLE , ranstr ),
61- "owner_org" : common . CIRCLE ,
62- "authors" : common . USER_NAME ,
71+ dataset_create ({"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
72+ "owner_org" : defaults [ "circle" ] ,
73+ "authors" : defaults [ "user_name" ] ,
6374 "license_id" : "CC0-1.0" ,
64- "groups" : [{"name" : common . COLLECTION }],
75+ "groups" : [{"name" : defaults [ "collection" ] }],
6576 },
6677 api = api ,
6778 resources = [dpath ],
6879 activate = True )
6980 db = db_api .APIInterrogator (api = api )
7081 # Positive test
7182 data = db .search_dataset (query = "dcoraid" ,
72- circles = [common . CIRCLE ],
73- collections = [common . COLLECTION ],
83+ circles = [defaults [ "circle" ] ],
84+ collections = [defaults [ "collection" ] ],
7485 )
7586 assert len (data ) >= 1
7687 for dd in data :
7788 if dd ["name" ].endswith (ranstr ):
7889 break
7990 else :
80- assert False , "{} not found!" .format (common . DATASET )
91+ assert False , "{} not found!" .format (defaults [ "dataset" ] )
8192 # Negative test
8293 data = db .search_dataset (query = "cliauwenlc_should_never_exist" ,
83- circles = [common . CIRCLE ],
84- collections = [common . COLLECTION ],
94+ circles = [defaults [ "circle" ] ],
95+ collections = [defaults [ "collection" ] ],
8596 )
8697 assert len (data ) == 0 , "search result for non-existent dataset?"
8798
8899
89100def test_search_dataset_limit ():
90101 api = common .get_api ()
91102 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
103+ defaults = common .get_test_defaults ()
92104 dataset_ids = []
93105 # Create three test datasets
94106 for _ in range (3 ):
95107 ds_dict = dataset_create (
96- {"title" : "{} {}" .format (common . TITLE , ranstr ),
97- "owner_org" : common . CIRCLE ,
98- "authors" : common . USER_NAME ,
108+ {"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
109+ "owner_org" : defaults [ "circle" ] ,
110+ "authors" : defaults [ "user_name" ] ,
99111 "license_id" : "CC0-1.0" ,
100- "groups" : [{"name" : common . COLLECTION }],
112+ "groups" : [{"name" : defaults [ "collection" ] }],
101113 },
102114 api = api ,
103115 resources = [dpath ],
104116 activate = True )
105117 dataset_ids .append (ds_dict ["id" ])
106118 db = db_api .APIInterrogator (api = api )
107119 data_limited = db .search_dataset (query = ranstr ,
108- circles = [common . CIRCLE ],
109- collections = [common . COLLECTION ],
120+ circles = [defaults [ "circle" ] ],
121+ collections = [defaults [ "collection" ] ],
110122 circle_collection_union = True ,
111123 limit = 2
112124 )
113125 assert len (data_limited ) == 2
114126 data_unlimited = db .search_dataset (query = ranstr ,
115- circles = [common . CIRCLE ],
116- collections = [common . COLLECTION ],
127+ circles = [defaults [ "circle" ] ],
128+ collections = [defaults [ "collection" ] ],
117129 circle_collection_union = True ,
118130 limit = 0
119131 )
@@ -123,28 +135,32 @@ def test_search_dataset_limit():
123135def test_search_dataset_limit_negative_error ():
124136 api = common .get_api ()
125137 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
138+ defaults = common .get_test_defaults ()
126139 # Create three test datasets
127140 dataset_create (
128- {"title" : "{} {}" .format (common . TITLE , ranstr ),
129- "owner_org" : common . CIRCLE ,
130- "authors" : common . USER_NAME ,
141+ {"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
142+ "owner_org" : defaults [ "circle" ] ,
143+ "authors" : defaults [ "user_name" ] ,
131144 "license_id" : "CC0-1.0" ,
132- "groups" : [{"name" : common . COLLECTION }],
145+ "groups" : [{"name" : defaults [ "collection" ] }],
133146 },
134147 api = api ,
135148 resources = [dpath ],
136149 activate = True )
137150 db = db_api .APIInterrogator (api = api )
138151 with pytest .raises (ValueError , match = "must be 0 or >0" ):
139152 db .search_dataset (query = ranstr ,
140- circles = [common . CIRCLE ],
141- collections = [common . COLLECTION ],
153+ circles = [defaults [ "circle" ] ],
154+ collections = [defaults [ "collection" ] ],
142155 circle_collection_union = True ,
143156 limit = - 1
144157 )
145158
146159
160+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
161+ reason = "No access to figshare-import circle" )
147162def test_search_dataset_only_one_filter_query ():
163+ # The figshare circle must have the testing user as a member
148164 api = common .get_api ()
149165 db = db_api .APIInterrogator (api = api )
150166 ds = db .search_dataset (filter_queries = [f"-creator_user_id:{ api .user_id } " ])
@@ -155,9 +171,10 @@ def test_search_dataset_only_one_filter_query():
155171 assert False , "Search did not return figshare-7771184-v2!"
156172
157173
174+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
175+ reason = "No access to figshare-import circle" )
158176def test_get_datasets_user_shared_figshare ():
159- """The figshare circle must have the user "dcoraid" as a member
160- """
177+ # The figshare circle must have the testing user as a member
161178 api = common .get_api ()
162179 db = db_api .APIInterrogator (api = api )
163180 datasets = db .get_datasets_user_shared ()
@@ -166,11 +183,3 @@ def test_get_datasets_user_shared_figshare():
166183 break
167184 else :
168185 assert False , "Search did not return figshare-7771184-v2!"
169-
170-
171- if __name__ == "__main__" :
172- # Run all tests
173- loc = locals ()
174- for key in list (loc .keys ()):
175- if key .startswith ("test_" ) and hasattr (loc [key ], "_call_" ):
176- loc [key ]()
0 commit comments