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
3240def test_get_users_anonymous ():
33- api = CKANAPI (server = "dcor-dev.mpl.mpg.de" )
41+ api = CKANAPI (server = common . SERVER ) # anonymous access
3442 db = db_api .APIInterrogator (api = api )
3543 with pytest .raises (errors .APIAuthorizationError , match = "Access denied" ):
3644 db .get_users ()
3745
3846
3947def test_public_api_interrogator ():
40- """This test uses the figshare datasets on SERVER"""
4148 api = common .get_api ()
4249 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 ()
50+ defaults = common .get_test_defaults ()
51+ assert defaults ["circle" ] in db .get_circles ()
52+ assert defaults ["collection" ] in db .get_collections ()
53+ assert defaults ["user" ] in db .get_users ()
4654
4755
4856def test_user_data ():
4957 """Test the user information"""
5058 api = common .get_api ()
5159 db = db_api .APIInterrogator (api = api )
5260 data = db .user_data
53- assert data ["fullname" ] == common .USER_NAME , "fullname not correct"
61+ defaults = common .get_test_defaults ()
62+ assert data ["fullname" ] == defaults ["user_name" ], "fullname not correct"
5463
5564
5665def test_search_dataset_basic ():
5766 api = common .get_api ()
5867 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
68+ defaults = common .get_test_defaults ()
5969 # Create a test dataset
60- dataset_create ({"title" : "{} {}" .format (common . TITLE , ranstr ),
61- "owner_org" : common . CIRCLE ,
62- "authors" : common . USER_NAME ,
70+ dataset_create ({"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
71+ "owner_org" : defaults [ "circle" ] ,
72+ "authors" : defaults [ "user_name" ] ,
6373 "license_id" : "CC0-1.0" ,
64- "groups" : [{"name" : common . COLLECTION }],
74+ "groups" : [{"name" : defaults [ "collection" ] }],
6575 },
6676 api = api ,
6777 resources = [dpath ],
6878 activate = True )
6979 db = db_api .APIInterrogator (api = api )
7080 # Positive test
7181 data = db .search_dataset (query = "dcoraid" ,
72- circles = [common . CIRCLE ],
73- collections = [common . COLLECTION ],
82+ circles = [defaults [ "circle" ] ],
83+ collections = [defaults [ "collection" ] ],
7484 )
7585 assert len (data ) >= 1
7686 for dd in data :
7787 if dd ["name" ].endswith (ranstr ):
7888 break
7989 else :
80- assert False , "{} not found!" .format (common . DATASET )
90+ assert False , "{} not found!" .format (defaults [ "dataset" ] )
8191 # Negative test
8292 data = db .search_dataset (query = "cliauwenlc_should_never_exist" ,
83- circles = [common . CIRCLE ],
84- collections = [common . COLLECTION ],
93+ circles = [defaults [ "circle" ] ],
94+ collections = [defaults [ "collection" ] ],
8595 )
8696 assert len (data ) == 0 , "search result for non-existent dataset?"
8797
8898
8999def test_search_dataset_limit ():
90100 api = common .get_api ()
91101 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
102+ defaults = common .get_test_defaults ()
92103 dataset_ids = []
93104 # Create three test datasets
94105 for _ in range (3 ):
95106 ds_dict = dataset_create (
96- {"title" : "{} {}" .format (common . TITLE , ranstr ),
97- "owner_org" : common . CIRCLE ,
98- "authors" : common . USER_NAME ,
107+ {"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
108+ "owner_org" : defaults [ "circle" ] ,
109+ "authors" : defaults [ "user_name" ] ,
99110 "license_id" : "CC0-1.0" ,
100- "groups" : [{"name" : common . COLLECTION }],
111+ "groups" : [{"name" : defaults [ "collection" ] }],
101112 },
102113 api = api ,
103114 resources = [dpath ],
104115 activate = True )
105116 dataset_ids .append (ds_dict ["id" ])
106117 db = db_api .APIInterrogator (api = api )
107118 data_limited = db .search_dataset (query = ranstr ,
108- circles = [common . CIRCLE ],
109- collections = [common . COLLECTION ],
119+ circles = [defaults [ "circle" ] ],
120+ collections = [defaults [ "collection" ] ],
110121 circle_collection_union = True ,
111122 limit = 2
112123 )
113124 assert len (data_limited ) == 2
114125 data_unlimited = db .search_dataset (query = ranstr ,
115- circles = [common . CIRCLE ],
116- collections = [common . COLLECTION ],
126+ circles = [defaults [ "circle" ] ],
127+ collections = [defaults [ "collection" ] ],
117128 circle_collection_union = True ,
118129 limit = 0
119130 )
@@ -123,28 +134,32 @@ def test_search_dataset_limit():
123134def test_search_dataset_limit_negative_error ():
124135 api = common .get_api ()
125136 ranstr = '' .join (random .choice ("0123456789" ) for _i in range (10 ))
137+ defaults = common .get_test_defaults ()
126138 # Create three test datasets
127139 dataset_create (
128- {"title" : "{} {}" .format (common . TITLE , ranstr ),
129- "owner_org" : common . CIRCLE ,
130- "authors" : common . USER_NAME ,
140+ {"title" : "{} {}" .format (defaults [ "title" ] , ranstr ),
141+ "owner_org" : defaults [ "circle" ] ,
142+ "authors" : defaults [ "user_name" ] ,
131143 "license_id" : "CC0-1.0" ,
132- "groups" : [{"name" : common . COLLECTION }],
144+ "groups" : [{"name" : defaults [ "collection" ] }],
133145 },
134146 api = api ,
135147 resources = [dpath ],
136148 activate = True )
137149 db = db_api .APIInterrogator (api = api )
138150 with pytest .raises (ValueError , match = "must be 0 or >0" ):
139151 db .search_dataset (query = ranstr ,
140- circles = [common . CIRCLE ],
141- collections = [common . COLLECTION ],
152+ circles = [defaults [ "circle" ] ],
153+ collections = [defaults [ "collection" ] ],
142154 circle_collection_union = True ,
143155 limit = - 1
144156 )
145157
146158
159+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
160+ reason = "No access to figshare-import circle" )
147161def test_search_dataset_only_one_filter_query ():
162+ # The figshare circle must have the testing user as a member
148163 api = common .get_api ()
149164 db = db_api .APIInterrogator (api = api )
150165 ds = db .search_dataset (filter_queries = [f"-creator_user_id:{ api .user_id } " ])
@@ -155,9 +170,10 @@ def test_search_dataset_only_one_filter_query():
155170 assert False , "Search did not return figshare-7771184-v2!"
156171
157172
173+ @pytest .mark .skipif (not HAS_FIGSHARE_ACCESS ,
174+ reason = "No access to figshare-import circle" )
158175def test_get_datasets_user_shared_figshare ():
159- """The figshare circle must have the user "dcoraid" as a member
160- """
176+ # The figshare circle must have the testing user as a member
161177 api = common .get_api ()
162178 db = db_api .APIInterrogator (api = api )
163179 datasets = db .get_datasets_user_shared ()
@@ -166,11 +182,3 @@ def test_get_datasets_user_shared_figshare():
166182 break
167183 else :
168184 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