|
1 | | -from ispyb.sqlalchemy import BLSession, Proposal |
| 1 | +from unittest import mock |
| 2 | + |
| 3 | +from ispyb.sqlalchemy import BLSession, DataCollectionGroup, Proposal |
2 | 4 | from pytest import mark |
3 | 5 | from sqlalchemy import select |
4 | 6 | from sqlalchemy.orm import Session |
5 | 7 |
|
6 | | -from murfey.server.ispyb import get_proposal_id, get_session_id |
7 | | -from tests.conftest import ExampleVisit |
| 8 | +from murfey.server.ispyb import TransportManager, get_proposal_id, get_session_id |
| 9 | +from tests.conftest import ExampleVisit, get_or_create_db_entry |
8 | 10 |
|
9 | 11 |
|
10 | 12 | def test_get_session_id( |
@@ -67,3 +69,32 @@ def test_get_sub_samples_from_visit(): |
67 | 69 | @mark.skip |
68 | 70 | def test_get_all_ongoing_visits(): |
69 | 71 | pass |
| 72 | + |
| 73 | + |
| 74 | +@mock.patch("workflows.transport.pika_transport.PikaTransport") |
| 75 | +def test_update_data_collection_group(mock_transport, ispyb_db_session: Session): |
| 76 | + get_or_create_db_entry( |
| 77 | + session=ispyb_db_session, |
| 78 | + table=DataCollectionGroup, |
| 79 | + insert_kwargs={ |
| 80 | + "dataCollectionGroup": 1, |
| 81 | + "experimentType": 1, |
| 82 | + }, |
| 83 | + ) |
| 84 | + |
| 85 | + transport_manager = TransportManager("PikaTransport") |
| 86 | + mock_transport().connect.assert_called_once() |
| 87 | + |
| 88 | + with mock.patch("murfey.server.ispyb.ISPyBSession", ispyb_db_session): |
| 89 | + transport_manager.do_update_data_collection_group( |
| 90 | + record=DataCollectionGroup(dataCollectionGroupId=1, experimentTypeId=2) |
| 91 | + ) |
| 92 | + |
| 93 | + final_dcg_entry = get_or_create_db_entry( |
| 94 | + session=ispyb_db_session, |
| 95 | + table=DataCollectionGroup, |
| 96 | + lookup_kwargs={ |
| 97 | + "dataCollectionGroup": 1, |
| 98 | + }, |
| 99 | + ) |
| 100 | + assert final_dcg_entry.experimentTypeId == 2 |
0 commit comments