Skip to content

Commit 96955ff

Browse files
committed
update tests for profile_paths variable
1 parent e2a030a commit 96955ff

3 files changed

Lines changed: 46 additions & 30 deletions

File tree

tests/test_api_routes.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def client():
1313
# Test POST API: /v1/ro_crates/{crate_id}/validation
1414

1515
@pytest.mark.parametrize(
16-
"crate_id, payload, status_code, response_json",
16+
"crate_id, payload, profiles_path, status_code, response_json",
1717
[
1818
(
1919
"crate-123", {
@@ -27,7 +27,9 @@ def client():
2727
"root_path": "base_path",
2828
"webhook_url": "https://webhook.example.com",
2929
"profile_name": "default"
30-
}, 202, {"message": "Validation in progress"}
30+
},
31+
None,
32+
202, {"message": "Validation in progress"}
3133
),
3234
(
3335
"crate-123", {
@@ -38,9 +40,11 @@ def client():
3840
"ssl": False,
3941
"bucket": "test_bucket"
4042
},
41-
"root_path": "base_path",
43+
"root_path": "base_path",
4244
"webhook_url": "https://webhook.example.com",
43-
}, 202, {"message": "Validation in progress"}
45+
},
46+
None,
47+
202, {"message": "Validation in progress"}
4448
),
4549
(
4650
"crate-123", {
@@ -51,9 +55,11 @@ def client():
5155
"ssl": False,
5256
"bucket": "test_bucket"
5357
},
54-
"root_path": "base_path",
58+
"root_path": "base_path",
5559
"profile_name": "default"
56-
}, 202, {"message": "Validation in progress"}
60+
},
61+
None,
62+
202, {"message": "Validation in progress"}
5763
),
5864
(
5965
"crate-123", {
@@ -66,7 +72,9 @@ def client():
6672
},
6773
"webhook_url": "https://webhook.example.com",
6874
"profile_name": "default"
69-
}, 202, {"message": "Validation in progress"}
75+
},
76+
None,
77+
202, {"message": "Validation in progress"}
7078
),
7179
(
7280
"crate-123", {
@@ -77,14 +85,17 @@ def client():
7785
"ssl": False,
7886
"bucket": "test_bucket"
7987
},
80-
}, 202, {"message": "Validation in progress"}
88+
},
89+
None,
90+
202, {"message": "Validation in progress"}
8191
),
8292
],
8393
ids=["validate_by_id", "validate_with_missing_profile_name",
8494
"validate_with_missing_webhook_url", "validate_with_missing_root_path",
8595
"validate_with_missing_root_path_and_profile_name_and_webhook_url"]
8696
)
87-
def test_validate_by_id_success(client: FlaskClient, crate_id: str, payload: dict, status_code: int, response_json: dict):
97+
def test_validate_by_id_success(client: FlaskClient, crate_id: str, payload: dict,
98+
profiles_path: str, status_code: int, response_json: dict):
8899
with patch("app.ro_crates.routes.post_routes.queue_ro_crate_validation_task") as mock_queue:
89100
mock_queue.return_value = (response_json, status_code)
90101

@@ -96,7 +107,7 @@ def test_validate_by_id_success(client: FlaskClient, crate_id: str, payload: dic
96107
webhook_url = payload["webhook_url"] if "webhook_url" in payload else None
97108
assert response.status_code == status_code
98109
assert response.json == response_json
99-
mock_queue.assert_called_once_with(minio_config, crate_id, root_path, profile_name, webhook_url)
110+
mock_queue.assert_called_once_with(minio_config, crate_id, root_path, profile_name, webhook_url, profiles_path)
100111

101112

102113
@pytest.mark.parametrize(

tests/test_services.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def flask_app():
2222
# Test function: queue_ro_crate_validation_task
2323

2424
@pytest.mark.parametrize(
25-
"crate_id, rocrate_exists, minio_client, delay_side_effects, payload, status_code, response_dict",
25+
"crate_id, rocrate_exists, minio_client, delay_side_effects, payload, profiles_path, status_code, response_dict",
2626
[
2727
(
2828
"crate123", True, "minio_client", None,
@@ -37,7 +37,9 @@ def flask_app():
3737
"root_path": "base_path",
3838
"webhook_url": "https://webhook.example.com",
3939
"profile_name": "default"
40-
}, 202, {"message": "Validation in progress"}
40+
},
41+
None,
42+
202, {"message": "Validation in progress"}
4143
),
4244
(
4345
"crate123", True, "minio_client", Exception("Celery down"),
@@ -52,7 +54,9 @@ def flask_app():
5254
"root_path": "base_path",
5355
"webhook_url": "https://webhook.example.com",
5456
"profile_name": "default"
55-
}, 500, {"error": "Celery down"}
57+
},
58+
None,
59+
500, {"error": "Celery down"}
5660
),
5761
],
5862
ids=["successful_queue", "celery_server_down"]
@@ -65,7 +69,7 @@ def test_queue_ro_crate_validation_task(
6569
mock_exists,
6670
mock_delay,
6771
flask_app: FlaskClient, crate_id: str, rocrate_exists: bool, minio_client: str,
68-
delay_side_effects: Exception, payload: dict, status_code: int, response_dict: dict
72+
delay_side_effects: Exception, payload: dict, profiles_path: str, status_code: int, response_dict: dict
6973
):
7074
mock_delay.side_effect = delay_side_effects
7175
mock_exists.return_value = rocrate_exists
@@ -76,11 +80,12 @@ def test_queue_ro_crate_validation_task(
7680
profile_name = payload["profile_name"] if "profile_name" in payload else None
7781
webhook_url = payload["webhook_url"] if "webhook_url" in payload else None
7882

79-
response, status_code = queue_ro_crate_validation_task(minio_config, crate_id, root_path, profile_name, webhook_url)
83+
response, status_code = queue_ro_crate_validation_task(minio_config, crate_id, root_path,
84+
profile_name, webhook_url, profiles_path)
8085

8186
mock_client.assert_called_once_with(minio_config)
8287
mock_exists.assert_called_once_with(minio_client, minio_config["bucket"], crate_id, root_path)
83-
mock_delay.assert_called_once_with(minio_config, crate_id, root_path, profile_name, webhook_url)
88+
mock_delay.assert_called_once_with(minio_config, crate_id, root_path, profile_name, webhook_url, profiles_path)
8489
assert status_code == status_code
8590
assert response.json == response_dict
8691

tests/test_validation_tasks.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
@pytest.mark.parametrize(
1919
"minio_config, crate_id, os_path_exists, os_path_isfile, os_path_isdir, " +
20-
"return_value, webhook, profile, val_success, val_result, minio_client",
20+
"return_value, webhook, profile, profiles_path, val_success, val_result, minio_client",
2121
[
2222
(
2323
{
@@ -28,7 +28,7 @@
2828
"bucket": "test_bucket"
2929
},
3030
"crate123", True, True, False, "/tmp/crate.zip",
31-
"https://example.com/hook", "profileA", True, '{"status": "valid"}',
31+
"https://example.com/hook", "profileA", None, True, '{"status": "valid"}',
3232
"minio_client"
3333
),
3434
(
@@ -40,7 +40,7 @@
4040
"bucket": "test_bucket"
4141
},
4242
"crate123", True, False, True, "/tmp/crate123",
43-
"https://example.com/hook", "profileA", True, '{"status": "valid"}',
43+
"https://example.com/hook", "profileA", None, True, '{"status": "valid"}',
4444
"minio_client"
4545
),
4646
(
@@ -52,7 +52,7 @@
5252
"bucket": "test_bucket"
5353
},
5454
"crate123", True, False, True, "/tmp/crate123",
55-
None, "profileA", True, '{"status": "valid"}',
55+
None, "profileA", None, True, '{"status": "valid"}',
5656
"minio_client"
5757
),
5858
],
@@ -80,7 +80,7 @@ def test_process_validation(
8080
mock_rmtree,
8181
mock_client,
8282
minio_config: dict, crate_id: str, os_path_exists: bool, os_path_isfile: bool, os_path_isdir: bool,
83-
return_value: str, webhook: str, profile: str, val_success: bool, val_result: str, minio_client: str
83+
return_value: str, webhook: str, profile: str, profiles_path: str, val_success: bool, val_result: str, minio_client: str
8484
):
8585
mock_exists.return_value = os_path_exists
8686
mock_isfile.return_value = os_path_isfile
@@ -93,11 +93,11 @@ def test_process_validation(
9393
mock_validation_result.to_json.return_value = val_result
9494
mock_validate.return_value = mock_validation_result
9595

96-
process_validation_task_by_id(minio_config, crate_id, "", profile, webhook)
96+
process_validation_task_by_id(minio_config, crate_id, "", profile, webhook, profiles_path)
9797

9898
mock_client.assert_called_once_with(minio_config)
9999
mock_fetch.assert_called_once_with(minio_client, minio_config["bucket"], crate_id, "")
100-
mock_validate.assert_called_once_with(return_value, profile)
100+
mock_validate.assert_called_once_with(return_value, profile, profiles_path=profiles_path)
101101
mock_update.assert_called_once_with(minio_client, minio_config["bucket"], crate_id, "", val_result)
102102
if webhook is not None:
103103
mock_webhook.assert_called_once_with(webhook, val_result)
@@ -113,7 +113,7 @@ def test_process_validation(
113113

114114
@pytest.mark.parametrize(
115115
"minio_config, crate_id, os_path_exists, os_path_isfile, os_path_isdir, return_fetch, "
116-
+ "webhook, profile, return_validate, validate_side_effect, fetch_side_effect, minio_client",
116+
+ "webhook, profile, profiles_path, return_validate, validate_side_effect, fetch_side_effect, minio_client",
117117
[
118118
(
119119
{
@@ -124,7 +124,7 @@ def test_process_validation(
124124
"bucket": "test_bucket"
125125
},
126126
"crate123", True, True, False, "/tmp/crate.zip",
127-
"https://example.com/hook", "profileA", "Validation failed", None, None,
127+
"https://example.com/hook", "profileA", None, "Validation failed", None, None,
128128
"minio_client"
129129
),
130130
(
@@ -136,7 +136,7 @@ def test_process_validation(
136136
"bucket": "test_bucket"
137137
},
138138
"crate123", True, True, False, "/tmp/crate.zip",
139-
"https://example.com/hook", "profileA", None, Exception("Unexpected error"), None,
139+
"https://example.com/hook", "profileA", None, None, Exception("Unexpected error"), None,
140140
"minio_client"
141141
),
142142
(
@@ -148,7 +148,7 @@ def test_process_validation(
148148
"bucket": "test_bucket"
149149
},
150150
"crate123", False, False, False, None,
151-
"https://example.com/hook", "profileA", None, None, Exception("MinIO fetch failed"),
151+
"https://example.com/hook", "profileA", None, None, None, Exception("MinIO fetch failed"),
152152
"minio_client"
153153
),
154154
],
@@ -177,7 +177,7 @@ def test_process_validation_failure(
177177
mock_rmtree,
178178
mock_client,
179179
minio_config: dict, crate_id: str, os_path_exists: bool, os_path_isfile: bool, os_path_isdir: bool,
180-
return_fetch: str, webhook: str, profile: str, return_validate: str,
180+
return_fetch: str, webhook: str, profile: str, profiles_path: str, return_validate: str,
181181
validate_side_effect: Exception, fetch_side_effect: Exception, minio_client: str
182182
):
183183
mock_exists.return_value = os_path_exists
@@ -195,10 +195,10 @@ def test_process_validation_failure(
195195
else:
196196
mock_validate.side_effect = validate_side_effect
197197

198-
process_validation_task_by_id(minio_config, crate_id, "", profile, webhook)
198+
process_validation_task_by_id(minio_config, crate_id, "", profile, webhook, profiles_path)
199199

200200
if fetch_side_effect is None:
201-
mock_validate.assert_called_once_with(return_fetch, profile)
201+
mock_validate.assert_called_once_with(return_fetch, profile, profiles_path=profiles_path)
202202
else:
203203
mock_validate.assert_not_called()
204204

0 commit comments

Comments
 (0)