Skip to content

Commit 06aad02

Browse files
committed
Changed variable names; added unit test for 'get_data_collection_group_ids()'
1 parent 1cd0aab commit 06aad02

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

tests/server/test_ispyb.py

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
1-
from ispyb.sqlalchemy import BLSession, Proposal
1+
from ispyb.sqlalchemy import BLSession, DataCollectionGroup, Proposal
22
from pytest import mark
33
from sqlalchemy import select
44
from sqlalchemy.orm import Session
55

6-
from murfey.server.ispyb import get_proposal_id, get_session_id
7-
from tests.conftest import ExampleVisit
6+
from murfey.server.ispyb import (
7+
get_data_collection_group_ids,
8+
get_proposal_id,
9+
get_session_id,
10+
)
11+
from tests.conftest import ExampleVisit, ISPyBTableValues
812

913

1014
def test_get_session_id(
1115
ispyb_db_session: Session,
1216
):
1317
# Manually get the BLSession ID for comparison
14-
query = (
18+
bl_session_id = (
1519
ispyb_db_session.execute(
1620
select(BLSession)
1721
.join(Proposal)
@@ -33,14 +37,14 @@ def test_get_session_id(
3337
visit_number=str(ExampleVisit.visit_number),
3438
db=ispyb_db_session,
3539
)
36-
assert query == result
40+
assert bl_session_id == result
3741

3842

3943
def test_get_proposal_id(
4044
ispyb_db_session: Session,
4145
):
4246
# Manually query the Proposal ID
43-
query = (
47+
proposal_id = (
4448
ispyb_db_session.execute(
4549
select(Proposal)
4650
.where(Proposal.proposalCode == ExampleVisit.proposal_code)
@@ -56,7 +60,7 @@ def test_get_proposal_id(
5660
proposal_number=ExampleVisit.proposal_number,
5761
db=ispyb_db_session,
5862
)
59-
assert query == result
63+
assert proposal_id == result
6064

6165

6266
@mark.skip
@@ -69,6 +73,33 @@ def test_get_all_ongoing_visits():
6973
pass
7074

7175

72-
@mark.skip
73-
def test_get_data_collection_group_ids():
74-
pass
76+
def test_get_data_collection_group_ids(
77+
ispyb_db_session: Session,
78+
):
79+
# Get the BLSession ID from test database
80+
bl_session_id = get_session_id(
81+
microscope=ExampleVisit.instrument_name,
82+
proposal_code=ExampleVisit.proposal_code,
83+
proposal_number=str(ExampleVisit.proposal_number),
84+
visit_number=str(ExampleVisit.visit_number),
85+
db=ispyb_db_session,
86+
)
87+
88+
# Add example data collections
89+
dcgs = [
90+
{
91+
"sessionId": bl_session_id,
92+
"experimentTypeId": ISPyBTableValues.experiment_types.get(name),
93+
}
94+
for name, id in ISPyBTableValues.experiment_types.items()
95+
]
96+
dcg_entries = [DataCollectionGroup(**dcg) for dcg in dcgs]
97+
for entry in dcg_entries:
98+
ispyb_db_session.add(entry)
99+
ispyb_db_session.commit()
100+
101+
# Test the function
102+
results = get_data_collection_group_ids(
103+
session_id=bl_session_id,
104+
)
105+
assert len(results) == len(dcg_entries)

0 commit comments

Comments
 (0)