@@ -203,41 +203,84 @@ def test_queue_metadata_json_errors(flask_app, crate_json: str, status_code: int
203203# Test function: get_ro_crate_validation_task
204204
205205@pytest .mark .parametrize (
206- "crate_id, crate_exists, validation_exists, validation_value, status_code, error_message" ,
206+ "minio_config, crate_id, crate_exists, validation_exists, " +
207+ "validation_value, status_code, error_message, minio_client" ,
207208 [
208- ("crate123" , True , True , {"status" : "valid" }, 200 , None ),
209- ("crate123" , False , False , None , 400 , "No RO-Crate with prefix: crate123" ),
210- ("crate123" , True , False , None , 400 , "No validation result yet for RO-Crate: crate123" ),
209+ (
210+ {
211+ "endpoint" : "localhost:9000" ,
212+ "accesskey" : "admin" ,
213+ "secret" : "password123" ,
214+ "ssl" : False ,
215+ "bucket" : "test_bucket"
216+ },
217+ "crate123" , True , True , {"status" : "valid" }, 200 , None ,
218+ "minio_client"
219+ ),
220+ (
221+ {
222+ "endpoint" : "localhost:9000" ,
223+ "accesskey" : "admin" ,
224+ "secret" : "password123" ,
225+ "ssl" : False ,
226+ "bucket" : "test_bucket"
227+ },
228+ "crate123" , False , False , None , 400 , "No RO-Crate with prefix: crate123" ,
229+ "minio_client"
230+ ),
231+ (
232+ {
233+ "endpoint" : "localhost:9000" ,
234+ "accesskey" : "admin" ,
235+ "secret" : "password123" ,
236+ "ssl" : False ,
237+ "bucket" : "test_bucket"
238+ },
239+ "crate123" , True , False , None , 400 , "No validation result yet for RO-Crate: crate123" ,
240+ "minio_client"
241+ ),
211242 ],
212243 ids = ["validation_exists" , "rocrate_missing" , "validation_missing" ]
213244)
214- def test_get_validation (flask_app , crate_id : str , crate_exists : bool ,
215- validation_exists : bool , validation_value : dict ,
216- status_code : int , error_message : str ):
217- with patch ("app.services.validation_service.check_ro_crate_exists" , return_value = crate_exists ) as mock_rocrate :
218- with patch ("app.services.validation_service.check_validation_exists" , return_value = validation_exists ) as mock_validation :
219- with patch ("app.services.validation_service.return_ro_crate_validation" , return_value = validation_value ) as mock_return :
220-
221- if crate_exists and validation_exists :
222- response , status = get_ro_crate_validation_task ("test_bucket" , crate_id , "base_path" )
223-
224- mock_return .assert_called_once_with ("test_bucket" , crate_id , "base_path" )
225- mock_rocrate .assert_called_once_with ("test_bucket" , crate_id , "base_path" )
226- mock_validation .assert_called_once_with ("test_bucket" , crate_id , "base_path" )
227-
228- assert status == status_code
229- assert response == validation_value
230-
231- else :
232- with pytest .raises (InvalidAPIUsage ) as exc_info :
233- get_ro_crate_validation_task ("test_bucket" , crate_id , "base_path" )
234-
235- assert exc_info .value .status_code == status_code
236- assert error_message in str (exc_info .value .message )
237-
238- mock_rocrate .assert_called_once_with ("test_bucket" , crate_id , "base_path" )
239- if crate_exists :
240- mock_validation .assert_called_once_with ("test_bucket" , crate_id , "base_path" )
241- else :
242- mock_validation .assert_not_called ()
243- mock_return .assert_not_called ()
245+ @patch ("app.services.validation_service.check_ro_crate_exists" )
246+ @patch ("app.services.validation_service.check_validation_exists" )
247+ @patch ("app.services.validation_service.return_ro_crate_validation" )
248+ @patch ("app.services.validation_service.get_minio_client" )
249+ def test_get_validation (
250+ mock_client ,
251+ mock_return ,
252+ mock_validation ,
253+ mock_rocrate ,
254+ flask_app , minio_config : dict , crate_id : str , crate_exists : bool ,
255+ validation_exists : bool , validation_value : dict ,
256+ status_code : int , error_message : str , minio_client : str
257+ ):
258+ mock_client .return_value = minio_client
259+ mock_rocrate .return_value = crate_exists
260+ mock_validation .return_value = validation_exists
261+ mock_return .return_value = validation_value
262+
263+ if crate_exists and validation_exists :
264+ response , status = get_ro_crate_validation_task (minio_config , crate_id , "base_path" )
265+
266+ mock_client .assert_called_once_with (minio_config )
267+ mock_return .assert_called_once_with (minio_client , minio_config ["bucket" ], crate_id , "base_path" )
268+ mock_rocrate .assert_called_once_with (minio_client , minio_config ["bucket" ], crate_id , "base_path" )
269+ mock_validation .assert_called_once_with (minio_client , minio_config ["bucket" ], crate_id , "base_path" )
270+
271+ assert status == status_code
272+ assert response == validation_value
273+
274+ else :
275+ with pytest .raises (InvalidAPIUsage ) as exc_info :
276+ get_ro_crate_validation_task (minio_config , crate_id , "base_path" )
277+
278+ assert exc_info .value .status_code == status_code
279+ assert error_message in str (exc_info .value .message )
280+
281+ mock_rocrate .assert_called_once_with (minio_client , minio_config ["bucket" ], crate_id , "base_path" )
282+ if crate_exists :
283+ mock_validation .assert_called_once_with (minio_client , minio_config ["bucket" ], crate_id , "base_path" )
284+ else :
285+ mock_validation .assert_not_called ()
286+ mock_return .assert_not_called ()
0 commit comments