Skip to content

Commit 406d510

Browse files
committed
More thorough test to verify that the database insertions on both Murfey and ISPyB have happened
1 parent df1f732 commit 406d510

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

tests/workflows/clem/test_register_preprocessing_results.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22
from typing import Any
33
from unittest.mock import MagicMock
44

5+
import ispyb.sqlalchemy as ISPyBDB
56
import pytest
67
from pytest_mock import MockerFixture
8+
from sqlalchemy import select as sa_select
79
from sqlalchemy.orm.session import Session as SQLAlchemySession
10+
from sqlmodel import select as sm_select
811
from sqlmodel.orm.session import Session as SQLModelSession
912

1013
import murfey.util.db as MurfeyDB
@@ -179,6 +182,7 @@ def test_run_with_db(
179182
ispyb_db_session: SQLAlchemySession,
180183
test_params: tuple[bool],
181184
):
185+
# Unpack test params
182186
(shuffle_message,) = test_params
183187

184188
# Create a session to insert for this test
@@ -253,9 +257,63 @@ def test_run_with_db(
253257
murfey_db=murfey_db_session,
254258
)
255259
assert result == {"success": True}
260+
256261
# Each message should call the align-and-merge workflow thrice
257262
# if gray and colour channels are both present
258263
assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len(
259264
colors
260265
)
266+
267+
# Both databases should have entries for data collection group, and grid squares
268+
# ISPyB database should additionally have an atlas entry
269+
murfey_dcg_search = murfey_db_session.exec(
270+
sm_select(MurfeyDB.DataCollectionGroup).where(
271+
MurfeyDB.DataCollectionGroup.session_id == murfey_session.id
272+
)
273+
).all()
274+
assert len(murfey_dcg_search) == 1
275+
murfey_gs_search = murfey_db_session.exec(
276+
sm_select(MurfeyDB.GridSquare).where(
277+
MurfeyDB.GridSquare.session_id == murfey_session.id
278+
)
279+
).all()
280+
assert len(murfey_gs_search) == len(preprocessing_messages) - 1
281+
282+
murfey_dcg = murfey_dcg_search[0]
283+
ispyb_dcg_search = (
284+
ispyb_db_session.execute(
285+
sa_select(ISPyBDB.DataCollectionGroup).where(
286+
ISPyBDB.DataCollectionGroup.dataCollectionGroupId == murfey_dcg.id
287+
)
288+
)
289+
.scalars()
290+
.all()
291+
)
292+
assert len(ispyb_dcg_search) == 1
293+
294+
ispyb_dcg = ispyb_dcg_search[0]
295+
ispyb_atlas_search = (
296+
ispyb_db_session.execute(
297+
sa_select(ISPyBDB.Atlas).where(
298+
ISPyBDB.Atlas.dataCollectionGroupId == ispyb_dcg.dataCollectionGroupId
299+
)
300+
)
301+
.scalars()
302+
.all()
303+
)
304+
assert len(ispyb_atlas_search) == 1
305+
306+
ispyb_atlas = ispyb_atlas_search[0]
307+
ispyb_gs_search = (
308+
ispyb_db_session.execute(
309+
sa_select(ISPyBDB.GridSquare).where(
310+
ISPyBDB.GridSquare.atlasId == ispyb_atlas.atlasId
311+
)
312+
)
313+
.scalars()
314+
.all()
315+
)
316+
assert len(ispyb_gs_search) == len(preprocessing_messages) - 1
317+
261318
murfey_db_session.close()
319+
ispyb_db_session.close()

0 commit comments

Comments
 (0)