Skip to content

Commit c77516e

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

File tree

1 file changed

+59
-3
lines changed

1 file changed

+59
-3
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 59 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import pytest
66
from pytest_mock import MockerFixture
77

8+
from murfey.server.run import _set_up_transport
89
from murfey.workflows.clem.register_preprocessing_results import (
910
_register_clem_image_series,
1011
_register_dcg_and_atlas,
@@ -20,9 +21,14 @@
2021

2122

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

0 commit comments

Comments
 (0)