@@ -12,23 +12,38 @@ def client():
1212
1313# Test POST API: /v1/ro_crates/{crate_id}/validation
1414
15- def test_validate_by_id_success (client ):
16- crate_id = "crate-123"
17- payload = {
18- "minio_bucket" : "test_bucket" ,
19- "root_path" : "base_path" ,
20- "webhook_url" : "https://webhook.example.com" ,
21- "profile_name" : "default"
22- }
23-
15+ @pytest .mark .parametrize (
16+ "crate_id, payload, status_code, response_json" ,
17+ [
18+ (
19+ "crate-123" , {
20+ "minio_bucket" : "test_bucket" ,
21+ "root_path" : "base_path" ,
22+ "webhook_url" : "https://webhook.example.com" ,
23+ "profile_name" : "default"
24+ }, 202 , {"message" : "Validation in progress" }
25+ ),
26+ (
27+ "crate-123" , {
28+ "minio_bucket" : "test_bucket"
29+ }, 202 , {"message" : "Validation in progress" }
30+ ),
31+ ],
32+ ids = ["validate_by_id" , "validate_with_missing_root_path_and_profile_name_and_webhook_url" ]
33+ )
34+ def test_validate_by_id_success (client , crate_id , payload , status_code , response_json ):
2435 with patch ("app.ro_crates.routes.post_routes.queue_ro_crate_validation_task" ) as mock_queue :
25- mock_queue .return_value = ({ "message" : "Validation in progress" }, 202 )
36+ mock_queue .return_value = (response_json , status_code )
2637
2738 response = client .post (f"/v1/ro_crates/{ crate_id } /validation" , json = payload )
2839
29- assert response .status_code == 202
30- assert response .json == {"message" : "Validation in progress" }
31- mock_queue .assert_called_once_with ("test_bucket" , "crate-123" , "base_path" , "default" , "https://webhook.example.com" )
40+ minio_bucket = payload ["minio_bucket" ] if "minio_bucket" in payload else None
41+ root_path = payload ["root_path" ] if "root_path" in payload else None
42+ profile_name = payload ["profile_name" ] if "profile_name" in payload else None
43+ webhook_url = payload ["webhook_url" ] if "webhook_url" in payload else None
44+ assert response .status_code == status_code
45+ assert response .json == response_json
46+ mock_queue .assert_called_once_with (minio_bucket , crate_id , root_path , profile_name , webhook_url )
3247
3348
3449@pytest .mark .parametrize (
@@ -60,20 +75,6 @@ def test_validate_fails_missing_elements(client, crate_id, payload, status_code)
6075 assert response .status_code == status_code
6176
6277
63- def test_validate_by_id_missing_root_path_and_profile_name_and_webhook_url (client ):
64- crate_id = "crate-123"
65- payload = {
66- "minio_bucket" : "test_bucket" ,
67- }
68-
69- with patch ("app.ro_crates.routes.post_routes.queue_ro_crate_validation_task" ) as mock_queue :
70- mock_queue .return_value = ({"message" : "Validation in progress" }, 202 )
71-
72- response = client .post (f"/v1/ro_crates/{ crate_id } /validation" , json = payload )
73-
74- assert response .status_code == 202
75- assert response .json == {"message" : "Validation in progress" }
76- mock_queue .assert_called_once_with ("test_bucket" , "crate-123" , None , None , None )
7778
7879
7980def test_validate_by_id_missing_profile_name (client ):
0 commit comments