Skip to content

Commit 0d3d779

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

File tree

1 file changed

+73
-4
lines changed

1 file changed

+73
-4
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 73 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,15 @@
55
import pytest
66
from pytest_mock import MockerFixture
77

8+
import murfey.util.db as MurfeyDB
9+
from murfey.server.run import _set_up_transport
810
from murfey.workflows.clem.register_preprocessing_results import (
911
_register_clem_image_series,
1012
_register_dcg_and_atlas,
1113
_register_grid_square,
1214
run,
1315
)
14-
from tests.conftest import ExampleVisit
16+
from tests.conftest import ExampleVisit, get_or_create_db_entry
1517

1618
visit_name = f"{ExampleVisit.proposal_code}{ExampleVisit.proposal_number}-{ExampleVisit.visit_number}"
1719
processed_dir_name = "processed"
@@ -20,9 +22,14 @@
2022

2123

2224
@pytest.fixture
23-
def preprocessing_messages(tmp_path: Path):
25+
def rsync_basepath(tmp_path: Path):
26+
return tmp_path / "data"
27+
28+
29+
@pytest.fixture
30+
def preprocessing_messages(rsync_basepath: Path):
2431
# Make directory to where data for current grid is stored
25-
visit_dir = tmp_path / "data" / "2020" / visit_name
32+
visit_dir = rsync_basepath / "2020" / visit_name
2633
processed_dir = visit_dir / processed_dir_name
2734
grid_dir = processed_dir / grid_name
2835
grid_dir.mkdir(parents=True, exist_ok=True)
@@ -147,4 +154,66 @@ def test_run(
147154
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
148155
colors
149156
)
150-
assert run
157+
158+
159+
def test_run_with_db(
160+
mocker: MockerFixture,
161+
preprocessing_messages: list[dict[str, Any]],
162+
rsync_basepath: Path,
163+
murfey_db_session,
164+
seed_murfey_db,
165+
ispyb_db_session_factory,
166+
ispyb_db_session,
167+
seed_ispyb_db,
168+
):
169+
# Mock out module-level functions
170+
mock_get_security_config = mocker.patch("murfey.server.ispyb.get_security_config")
171+
mock_get_security_config.return_value = MagicMock()
172+
mock_url = mocker.patch("murfey.server.ispyb.url")
173+
mock_url.return_value = MagicMock()
174+
mock_create_engine = mocker.patch("murfey.server.ispyb.create_engine")
175+
mock_create_engine.return_value = MagicMock()
176+
177+
# Mock out the machine config used in the helper sanitisation function
178+
mock_get_machine_config = mocker.patch("murfey.workflows.clem.get_machine_config")
179+
mock_machine_config = MagicMock()
180+
mock_machine_config.rsync_basepath = rsync_basepath
181+
mock_get_machine_config.return_value = {
182+
ExampleVisit.instrument_name: mock_machine_config,
183+
}
184+
# Mock the ISPyB connection
185+
mock_ispyb_sessionmaker = mocker.patch("murfey.server.ispyb.sessionmaker")
186+
mock_ispyb_sessionmaker.return_value = ispyb_db_session_factory
187+
mock_ispyb_sessionmaker.return_value.return_value = ispyb_db_session
188+
189+
# Populate the Murfey database
190+
murfey_session_entry: MurfeyDB.Session = get_or_create_db_entry(
191+
murfey_db_session,
192+
MurfeyDB.Session,
193+
lookup_kwargs={"id": ExampleVisit.murfey_session_id},
194+
)
195+
murfey_session_entry.visit = visit_name
196+
murfey_session_entry.name = visit_name
197+
murfey_session_entry.instrument_name = ExampleVisit.instrument_name
198+
murfey_db_session.add(murfey_session_entry)
199+
murfey_db_session.commit()
200+
201+
# Mock the align and merge workflow call
202+
mock_align_and_merge_call = mocker.patch(
203+
"murfey.workflows.clem.register_preprocessing_results.submit_cluster_request"
204+
)
205+
206+
# Set up the transport manager
207+
_set_up_transport("PikaTransport")
208+
209+
# Run the function
210+
for message in preprocessing_messages:
211+
result = run(
212+
message=message,
213+
murfey_db=murfey_db_session,
214+
)
215+
assert result == {"success": True}
216+
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
217+
colors
218+
)
219+
murfey_db_session.close()

0 commit comments

Comments
 (0)