|
2 | 2 | from typing import Any |
3 | 3 | from unittest.mock import MagicMock |
4 | 4 |
|
| 5 | +import ispyb.sqlalchemy as ISPyBDB |
5 | 6 | import pytest |
6 | 7 | from pytest_mock import MockerFixture |
| 8 | +from sqlalchemy import select as sa_select |
7 | 9 | from sqlalchemy.orm.session import Session as SQLAlchemySession |
| 10 | +from sqlmodel import select as sm_select |
8 | 11 | from sqlmodel.orm.session import Session as SQLModelSession |
9 | 12 |
|
10 | 13 | import murfey.util.db as MurfeyDB |
@@ -179,6 +182,7 @@ def test_run_with_db( |
179 | 182 | ispyb_db_session: SQLAlchemySession, |
180 | 183 | test_params: tuple[bool], |
181 | 184 | ): |
| 185 | + # Unpack test params |
182 | 186 | (shuffle_message,) = test_params |
183 | 187 |
|
184 | 188 | # Create a session to insert for this test |
@@ -253,9 +257,63 @@ def test_run_with_db( |
253 | 257 | murfey_db=murfey_db_session, |
254 | 258 | ) |
255 | 259 | assert result == {"success": True} |
| 260 | + |
256 | 261 | # Each message should call the align-and-merge workflow thrice |
257 | 262 | # if gray and colour channels are both present |
258 | 263 | assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len( |
259 | 264 | colors |
260 | 265 | ) |
| 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 | + |
261 | 318 | murfey_db_session.close() |
| 319 | + ispyb_db_session.close() |
0 commit comments