Skip to content

Commit d206593

Browse files
committed
Attempt to run test on this workflow with the Murfey and ISPyB databases
1 parent 4038cda commit d206593

File tree

1 file changed

+63
-3
lines changed

1 file changed

+63
-3
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
import importlib
12
from pathlib import Path
23
from typing import Any
34
from unittest.mock import MagicMock
45

56
import pytest
67
from pytest_mock import MockerFixture
78

9+
import murfey.workflows.clem.register_preprocessing_results
10+
from murfey.server.run import _set_up_transport
811
from murfey.workflows.clem.register_preprocessing_results import (
912
_register_clem_image_series,
1013
_register_dcg_and_atlas,
@@ -20,9 +23,14 @@
2023

2124

2225
@pytest.fixture
23-
def preprocessing_messages(tmp_path: Path):
26+
def rsync_basepath(tmp_path: Path):
27+
return tmp_path / "data"
28+
29+
30+
@pytest.fixture
31+
def preprocessing_messages(rsync_basepath: Path):
2432
# Make directory to where data for current grid is stored
25-
visit_dir = tmp_path / "data" / "2020" / visit_name
33+
visit_dir = rsync_basepath / "2020" / visit_name
2634
processed_dir = visit_dir / processed_dir_name
2735
grid_dir = processed_dir / grid_name
2836
grid_dir.mkdir(parents=True, exist_ok=True)
@@ -147,4 +155,56 @@ def test_run(
147155
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
148156
colors
149157
)
150-
assert run
158+
159+
160+
def test_run_with_db(
161+
mocker: MockerFixture,
162+
preprocessing_messages: list[dict[str, Any]],
163+
rsync_basepath: Path,
164+
murfey_db_session,
165+
seed_murfey_db,
166+
ispyb_db_session_factory,
167+
ispyb_db_session,
168+
seed_ispyb_db,
169+
):
170+
# Mock out module-level functions
171+
mock_get_security_config = mocker.patch("murfey.server.ispyb.get_security_config")
172+
mock_get_security_config.return_value = MagicMock()
173+
mock_url = mocker.patch("murfey.server.ispyb.url")
174+
mock_url.return_value = MagicMock()
175+
mock_create_engine = mocker.patch("murfey.server.ispyb.create_engine")
176+
mock_create_engine.return_value = MagicMock()
177+
178+
# Mock out the machine config used in the helper sanitisation function
179+
mock_get_machine_config = mocker.patch("murfey.workflows.clem.get_machine_config")
180+
mock_machine_config = MagicMock()
181+
mock_machine_config.rsync_basepath = rsync_basepath
182+
mock_get_machine_config.return_value = {
183+
"": mock_machine_config,
184+
}
185+
# Mock the ISPyB connection
186+
mock_ispyb_sessionmaker = mocker.patch("murfey.server.ispyb.sessionmaker")
187+
mock_ispyb_sessionmaker.return_value = ispyb_db_session_factory
188+
mock_ispyb_sessionmaker.return_value.return_value = ispyb_db_session
189+
190+
# Mock the align and merge workflow call
191+
mock_align_and_merge_call = mocker.patch(
192+
"murfey.workflows.clem.register_preprocessing_results.submit_cluster_request"
193+
)
194+
195+
# Set up the transport manager
196+
_set_up_transport("PikaTransport")
197+
# Reload the module to re-import it correctly
198+
importlib.reload(murfey.workflows.clem.register_preprocessing_results)
199+
200+
# Run the function
201+
for message in preprocessing_messages:
202+
result = run(
203+
message=message,
204+
murfey_db=murfey_db_session,
205+
)
206+
assert result == {"success": True}
207+
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
208+
colors
209+
)
210+
murfey_db_session.close()

0 commit comments

Comments
 (0)