Skip to content

Commit cdd219b

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

File tree

1 file changed

+73
-3
lines changed

1 file changed

+73
-3
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,14 @@
2020

2121

2222
@pytest.fixture
23-
def preprocessing_messages(tmp_path: Path):
23+
def rsync_basepath(tmp_path: Path):
24+
return tmp_path / "data"
25+
26+
27+
@pytest.fixture
28+
def preprocessing_messages(rsync_basepath: Path):
2429
# Make directory to where data for current grid is stored
25-
visit_dir = tmp_path / "data" / "2020" / visit_name
30+
visit_dir = rsync_basepath / "2020" / visit_name
2631
processed_dir = visit_dir / processed_dir_name
2732
grid_dir = processed_dir / grid_name
2833
grid_dir.mkdir(parents=True, exist_ok=True)
@@ -147,4 +152,69 @@ def test_run(
147152
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
148153
colors
149154
)
150-
assert run
155+
156+
157+
def test_run_with_db(
158+
mocker: MockerFixture,
159+
preprocessing_messages: list[dict[str, Any]],
160+
rsync_basepath: Path,
161+
murfey_db_session,
162+
seed_murfey_db,
163+
ispyb_db_session_factory,
164+
ispyb_db_session,
165+
seed_ispyb_db,
166+
):
167+
# Mock out module-level functions
168+
mock_get_security_config = mocker.patch("murfey.server.ispyb.get_security_config")
169+
mock_get_security_config.return_value = MagicMock()
170+
mock_url = mocker.patch("murfey.server.ispyb.url")
171+
mock_url.return_value = MagicMock()
172+
mock_create_engine = mocker.patch("murfey.server.ispyb.create_engine")
173+
mock_create_engine.return_value = MagicMock()
174+
175+
# Mock the ISPyB connection
176+
mock_ispyb_sessionmaker = mocker.patch(
177+
"murfey.server.ispyb.sessionmaker", new_callable=MagicMock()
178+
)
179+
mock_ispyb_sessionmaker.return_value.return_value = ispyb_db_session
180+
181+
# Mock out the machine config used in the helper sanitisation function
182+
mock_get_machine_config = mocker.patch("murfey.workflows.clem.get_machine_config")
183+
mock_machine_config = MagicMock()
184+
mock_machine_config.rsync_basepath = rsync_basepath
185+
mock_get_machine_config.return_value = {
186+
"": mock_machine_config,
187+
}
188+
189+
# Mock the align and merge workflow call
190+
mock_align_and_merge_call = mocker.patch(
191+
"murfey.workflows.clem.register_preprocessing_results.submit_cluster_request"
192+
)
193+
194+
# Patch the TransportManager object in the workflows called
195+
from murfey.server.ispyb import TransportManager
196+
197+
mocker.patch(
198+
"murfey.workflows.clem.register_preprocessing_results._transport_object",
199+
new=TransportManager("PikaTransport"),
200+
)
201+
mocker.patch(
202+
"murfey.workflows.register_data_collection_group._transport_object",
203+
new=TransportManager("PikaTransport"),
204+
)
205+
mocker.patch(
206+
"murfey.workflows.register_atlas_update._transport_object",
207+
new=TransportManager("PikaTransport"),
208+
)
209+
210+
# Run the function
211+
for message in preprocessing_messages:
212+
result = run(
213+
message=message,
214+
murfey_db=murfey_db_session,
215+
)
216+
assert result == {"success": True}
217+
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
218+
colors
219+
)
220+
murfey_db_session.close()

0 commit comments

Comments
 (0)