|
| 1 | +from unittest.mock import MagicMock |
| 2 | + |
| 3 | +import pytest |
| 4 | +from pytest_mock import MockerFixture |
| 5 | + |
| 6 | +from murfey.workflows.register_experiment_type_update import run |
| 7 | + |
| 8 | +register_experiment_type_update_matrix = (0, 1, None) |
| 9 | + |
| 10 | + |
| 11 | +@pytest.mark.parametrize("insert_dcg", register_experiment_type_update_matrix) |
| 12 | +def test_run( |
| 13 | + mocker: MockerFixture, |
| 14 | + insert_dcg: int | None, |
| 15 | +): |
| 16 | + # Mock the transport object functions |
| 17 | + mock_transport_object = mocker.patch( |
| 18 | + "murfey.workflows.register_experiment_type_update._transport_object" |
| 19 | + ) |
| 20 | + mock_transport_object.do_update_data_collection_group.return_value = { |
| 21 | + "return_value": insert_dcg, |
| 22 | + } |
| 23 | + mock_ispyb = mocker.patch( |
| 24 | + "murfey.workflows.register_experiment_type_update.ISPyBDB" |
| 25 | + ) |
| 26 | + mock_ispyb.DataCollectionGroup.return_value = "ispyb_dcg" |
| 27 | + |
| 28 | + # Mock the Murfey database |
| 29 | + mock_murfey_db = MagicMock() |
| 30 | + |
| 31 | + # Run the function and check the results and calls |
| 32 | + message = { |
| 33 | + "dcgid": 1, |
| 34 | + "experiment_type_id": 0, |
| 35 | + } |
| 36 | + result = run(message=message, murfey_db=mock_murfey_db) |
| 37 | + mock_ispyb.DataCollectionGroup.assert_called_once_with( |
| 38 | + dataCollectionGroupId=1, experimentTypeId=0 |
| 39 | + ) |
| 40 | + mock_transport_object.do_update_data_collection_group.assert_called_once_with( |
| 41 | + "ispyb_dcg" |
| 42 | + ) |
| 43 | + if insert_dcg is not None: |
| 44 | + assert result == {"success": True} |
| 45 | + else: |
| 46 | + assert result == {"success": False, "requeue": True} |
0 commit comments