|
5 | 5 | import pytest |
6 | 6 | from pytest_mock import MockerFixture |
7 | 7 |
|
| 8 | +from murfey.server.run import _set_up_transport |
8 | 9 | from murfey.workflows.clem.register_preprocessing_results import ( |
9 | 10 | _register_clem_image_series, |
10 | 11 | _register_dcg_and_atlas, |
|
20 | 21 |
|
21 | 22 |
|
22 | 23 | @pytest.fixture |
23 | | -def preprocessing_messages(tmp_path: Path): |
| 24 | +def rsync_basepath(tmp_path: Path): |
| 25 | + return tmp_path / "data" |
| 26 | + |
| 27 | + |
| 28 | +@pytest.fixture |
| 29 | +def preprocessing_messages(rsync_basepath: Path): |
24 | 30 | # Make directory to where data for current grid is stored |
25 | | - visit_dir = tmp_path / "data" / "2020" / visit_name |
| 31 | + visit_dir = rsync_basepath / "2020" / visit_name |
26 | 32 | processed_dir = visit_dir / processed_dir_name |
27 | 33 | grid_dir = processed_dir / grid_name |
28 | 34 | grid_dir.mkdir(parents=True, exist_ok=True) |
@@ -147,4 +153,54 @@ def test_run( |
147 | 153 | assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len( |
148 | 154 | colors |
149 | 155 | ) |
150 | | - assert run |
| 156 | + |
| 157 | + |
| 158 | +def test_run_with_db( |
| 159 | + mocker: MockerFixture, |
| 160 | + preprocessing_messages: list[dict[str, Any]], |
| 161 | + rsync_basepath: Path, |
| 162 | + murfey_db_session, |
| 163 | + seed_murfey_db, |
| 164 | + ispyb_db_session_factory, |
| 165 | + ispyb_db_session, |
| 166 | + seed_ispyb_db, |
| 167 | +): |
| 168 | + # Mock out module-level functions |
| 169 | + mock_get_security_config = mocker.patch("murfey.server.ispyb.get_security_config") |
| 170 | + mock_get_security_config.return_value = MagicMock() |
| 171 | + mock_url = mocker.patch("murfey.server.ispyb.url") |
| 172 | + mock_url.return_value = MagicMock() |
| 173 | + mock_create_engine = mocker.patch("murfey.server.ispyb.create_engine") |
| 174 | + mock_create_engine.return_value = MagicMock() |
| 175 | + |
| 176 | + # Mock out the machine config used in the helper sanitisation function |
| 177 | + mock_get_machine_config = mocker.patch("murfey.workflows.clem.get_machine_config") |
| 178 | + mock_machine_config = MagicMock() |
| 179 | + mock_machine_config.rsync_basepath = rsync_basepath |
| 180 | + mock_get_machine_config.return_value = { |
| 181 | + ExampleVisit.instrument_name: mock_machine_config, |
| 182 | + } |
| 183 | + # Mock the ISPyB connection |
| 184 | + mock_ispyb_sessionmaker = mocker.patch("murfey.server.ispyb.sessionmaker") |
| 185 | + mock_ispyb_sessionmaker.return_value = ispyb_db_session_factory |
| 186 | + mock_ispyb_sessionmaker.return_value.return_value = ispyb_db_session |
| 187 | + |
| 188 | + # Mock the align and merge workflow call |
| 189 | + mock_align_and_merge_call = mocker.patch( |
| 190 | + "murfey.workflows.clem.register_preprocessing_results.submit_cluster_request" |
| 191 | + ) |
| 192 | + |
| 193 | + # Set up the transport manager |
| 194 | + _set_up_transport("PikaTransport") |
| 195 | + |
| 196 | + # Run the function |
| 197 | + for message in preprocessing_messages: |
| 198 | + result = run( |
| 199 | + message=message, |
| 200 | + murfey_db=murfey_db_session, |
| 201 | + ) |
| 202 | + assert result == {"success": True} |
| 203 | + assert mock_align_and_merge_call.call_count == len(preprocessing_messages) * len( |
| 204 | + colors |
| 205 | + ) |
| 206 | + murfey_db_session.close() |
0 commit comments