Skip to content

Commit 26f3a14

Browse files
committed
pass minio config to validation celery task
1 parent 5bc2621 commit 26f3a14

2 files changed

Lines changed: 53 additions & 16 deletions

File tree

app/tasks/validation_tasks.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@
2929

3030
@celery.task
3131
def process_validation_task_by_id(
32-
minio_bucket: str, crate_id: str, root_path: str, profile_name: str | None, webhook_url: str | None
32+
minio_config: dict, crate_id: str, root_path: str, profile_name: str | None, webhook_url: str | None
3333
) -> None:
3434
"""
3535
Background task to process the RO-Crate validation by ID.
3636
37-
:param minio_bucket: The MinIO bucket containing the RO-Crate.
37+
:param minio_config: The MinIO configuration.
3838
:param crate_id: The ID of the RO-Crate to validate.
3939
:param root_path: The root path containing the RO-Crate.
4040
:param profile_name: The name of the validation profile to use. Defaults to None.
@@ -45,11 +45,13 @@ def process_validation_task_by_id(
4545

4646
# TODO: Split try statements: (1) fetch and validate; (2) write to minio; (3) webhook
4747

48+
minio_client = get_minio_client(minio_config)
49+
4850
file_path = None
4951

5052
try:
5153
# Fetch the RO-Crate from MinIO using the provided ID:
52-
file_path = fetch_ro_crate_from_minio(minio_bucket, crate_id, root_path)
54+
file_path = fetch_ro_crate_from_minio(minio_client, minio_config["bucket"], crate_id, root_path)
5355

5456
logging.info(f"Processing validation task for {file_path}")
5557

@@ -67,7 +69,7 @@ def process_validation_task_by_id(
6769
logging.info(f"RO Crate {crate_id} is invalid.")
6870

6971
# Update the validation status in MinIO:
70-
update_validation_status_in_minio(minio_bucket, crate_id, root_path, validation_result.to_json())
72+
update_validation_status_in_minio(minio_client, minio_config["bucket"], crate_id, root_path, validation_result.to_json())
7173

7274
# TODO: Prepare the data to send to the webhook, and send the webhook notification.
7375

tests/test_validation_tasks.py

Lines changed: 47 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,49 @@
1616
# Test function: process_validation_task_by_id
1717

1818
@pytest.mark.parametrize(
19-
"crate_id, os_path_exists, os_path_isfile, os_path_isdir, return_value, webhook, profile, val_success, val_result",
19+
"minio_config, crate_id, os_path_exists, os_path_isfile, os_path_isdir, " +
20+
"return_value, webhook, profile, val_success, val_result, minio_client",
2021
[
21-
("crate123", True, True, False, "/tmp/crate.zip",
22-
"https://example.com/hook", "profileA", True, '{"status": "valid"}'),
23-
("crate123", True, False, True, "/tmp/crate123",
24-
"https://example.com/hook", "profileA", True, '{"status": "valid"}'),
25-
("crate123", True, False, True, "/tmp/crate123",
26-
None, "profileA", True, '{"status": "valid"}'),
22+
(
23+
{
24+
"endpoint": "localhost:9000",
25+
"accesskey": "admin",
26+
"secret": "password123",
27+
"ssl": False,
28+
"bucket": "test_bucket"
29+
},
30+
"crate123", True, True, False, "/tmp/crate.zip",
31+
"https://example.com/hook", "profileA", True, '{"status": "valid"}',
32+
"minio_client"
33+
),
34+
(
35+
{
36+
"endpoint": "localhost:9000",
37+
"accesskey": "admin",
38+
"secret": "password123",
39+
"ssl": False,
40+
"bucket": "test_bucket"
41+
},
42+
"crate123", True, False, True, "/tmp/crate123",
43+
"https://example.com/hook", "profileA", True, '{"status": "valid"}',
44+
"minio_client"
45+
),
46+
(
47+
{
48+
"endpoint": "localhost:9000",
49+
"accesskey": "admin",
50+
"secret": "password123",
51+
"ssl": False,
52+
"bucket": "test_bucket"
53+
},
54+
"crate123", True, False, True, "/tmp/crate123",
55+
None, "profileA", True, '{"status": "valid"}',
56+
"minio_client"
57+
),
2758
],
2859
ids=["successful_validation_zip", "successful_validation_dir", "successful_validation_nowebhook"]
2960
)
61+
@mock.patch("app.tasks.validation_tasks.get_minio_client")
3062
@mock.patch("app.tasks.validation_tasks.shutil.rmtree")
3163
@mock.patch("app.tasks.validation_tasks.os.remove")
3264
@mock.patch("app.tasks.validation_tasks.os.path.exists")
@@ -46,24 +78,27 @@ def test_process_validation(
4678
mock_exists,
4779
mock_remove,
4880
mock_rmtree,
49-
crate_id: str, os_path_exists: bool, os_path_isfile: bool, os_path_isdir: bool,
50-
return_value: str, webhook: str, profile: str, val_success: bool, val_result: str
81+
mock_client,
82+
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
5184
):
5285
mock_exists.return_value = os_path_exists
5386
mock_isfile.return_value = os_path_isfile
5487
mock_isdir.return_value = os_path_isdir
5588
mock_fetch.return_value = return_value
89+
mock_client.return_value = minio_client
5690

5791
mock_validation_result = mock.Mock()
5892
mock_validation_result.has_issues.return_value = val_success
5993
mock_validation_result.to_json.return_value = val_result
6094
mock_validate.return_value = mock_validation_result
6195

62-
process_validation_task_by_id("test_bucket", crate_id, "", profile, webhook)
96+
process_validation_task_by_id(minio_config, crate_id, "", profile, webhook)
6397

64-
mock_fetch.assert_called_once_with("test_bucket", crate_id, "")
98+
mock_client.assert_called_once_with(minio_config)
99+
mock_fetch.assert_called_once_with(minio_client, minio_config["bucket"], crate_id, "")
65100
mock_validate.assert_called_once_with(return_value, profile)
66-
mock_update.assert_called_once_with("test_bucket", crate_id, "", val_result)
101+
mock_update.assert_called_once_with(minio_client, minio_config["bucket"], crate_id, "", val_result)
67102
if webhook is not None:
68103
mock_webhook.assert_called_once_with(webhook, val_result)
69104
else:

0 commit comments

Comments
 (0)