Skip to content

Commit 8f21e09

Browse files
committed
Try and test ispyb db update
1 parent 1356eba commit 8f21e09

File tree

1 file changed

+34
-3
lines changed

1 file changed

+34
-3
lines changed

tests/server/test_ispyb.py

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
from ispyb.sqlalchemy import BLSession, Proposal
1+
from unittest import mock
2+
3+
from ispyb.sqlalchemy import BLSession, DataCollectionGroup, Proposal
24
from pytest import mark
35
from sqlalchemy import select
46
from sqlalchemy.orm import Session
57

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
810

911

1012
def test_get_session_id(
@@ -67,3 +69,32 @@ def test_get_sub_samples_from_visit():
6769
@mark.skip
6870
def test_get_all_ongoing_visits():
6971
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

Comments
 (0)