Skip to content

Commit 988137a

Browse files
committed
Run test workflow with Murfey and ISPyB databases
1 parent 01e6798 commit 988137a

File tree

1 file changed

+71
-3
lines changed

1 file changed

+71
-3
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import pytest
66
from pytest_mock import MockerFixture
7+
from sqlalchemy.orm.session import Session as SQLAlchemySession
8+
from sqlmodel.orm.session import Session as SQLModelSession
79

810
from murfey.workflows.clem.register_preprocessing_results import (
911
_register_clem_image_series,
@@ -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,65 @@ 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+
mock_ispyb_credentials,
164+
murfey_db_session: SQLModelSession,
165+
seed_murfey_db,
166+
ispyb_db_session: SQLAlchemySession,
167+
seed_ispyb_db,
168+
):
169+
# Mock out module-level functions
170+
mock_security_config = MagicMock()
171+
mock_security_config.ispyb_credentials = mock_ispyb_credentials
172+
mock_get_security_config = mocker.patch("murfey.server.ispyb.get_security_config")
173+
mock_get_security_config.return_value = mock_security_config
174+
175+
# Mock the ISPyB connection
176+
mock_ispyb_sessionmaker = mocker.patch("murfey.server.ispyb.sessionmaker")
177+
mock_ispyb_sessionmaker.return_value.return_value = ispyb_db_session
178+
179+
# Mock out the machine config used in the helper sanitisation function
180+
mock_get_machine_config = mocker.patch("murfey.workflows.clem.get_machine_config")
181+
mock_machine_config = MagicMock()
182+
mock_machine_config.rsync_basepath = rsync_basepath
183+
mock_get_machine_config.return_value = {
184+
"": mock_machine_config,
185+
}
186+
187+
# Mock the align and merge workflow call
188+
mock_align_and_merge_call = mocker.patch(
189+
"murfey.workflows.clem.register_preprocessing_results.submit_cluster_request"
190+
)
191+
192+
# Patch the TransportManager object in the workflows called
193+
from murfey.server.ispyb import TransportManager
194+
195+
mocker.patch(
196+
"murfey.workflows.clem.register_preprocessing_results._transport_object",
197+
new=TransportManager("PikaTransport"),
198+
)
199+
mocker.patch(
200+
"murfey.workflows.register_data_collection_group._transport_object",
201+
new=TransportManager("PikaTransport"),
202+
)
203+
mocker.patch(
204+
"murfey.workflows.register_atlas_update._transport_object",
205+
new=TransportManager("PikaTransport"),
206+
)
207+
208+
# Run the function
209+
for message in preprocessing_messages:
210+
result = run(
211+
message=message,
212+
murfey_db=murfey_db_session,
213+
)
214+
assert result == {"success": True}
215+
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
216+
colors
217+
)
218+
murfey_db_session.close()

0 commit comments

Comments
 (0)