Skip to content

Commit e82bd67

Browse files
committed
Simplified the test for the 'get_session_id()' function, now that the database is pre-populated
1 parent 5825457 commit e82bd67

File tree

1 file changed

+20
-28
lines changed

1 file changed

+20
-28
lines changed

tests/server/test_ispyb.py

Lines changed: 20 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,34 @@
1-
from ispyb.sqlalchemy import BLSession, Person, Proposal
1+
from ispyb.sqlalchemy import BLSession, Proposal
2+
from sqlmodel import Session, select
23

34
from murfey.server.ispyb import get_session_id
5+
from tests.conftest import ExampleVisit
46

57

68
def test_get_session_id(
7-
ispyb_session,
9+
ispyb_db: Session,
810
):
9-
10-
# Create some values to put into BLSession and Proposal
11-
# 'Person' is a required table
12-
person_db_entry = Person(
13-
login="murfey",
14-
)
15-
ispyb_session.add(person_db_entry)
16-
ispyb_session.commit()
17-
18-
proposal_db_entry = Proposal(
19-
personId=person_db_entry.personId,
20-
proposalCode="cm",
21-
proposalNumber="12345",
22-
)
23-
ispyb_session.add(proposal_db_entry)
24-
ispyb_session.commit()
25-
26-
bl_session_db_entry = BLSession(
27-
proposalId=proposal_db_entry.proposalId,
28-
beamLineName="murfey",
29-
visit_number=6,
11+
# Manually get the BLSession ID for comparison
12+
result = (
13+
ispyb_db.exec(
14+
select(BLSession)
15+
.join(Proposal)
16+
.where(BLSession.proposalId == Proposal.proposalId)
17+
.where(BLSession.beamLineName == ExampleVisit.instrument_name)
18+
.where(Proposal.proposalCode == ExampleVisit.proposal_code)
19+
.where(Proposal.proposalNumber == str(ExampleVisit.proposal_number))
20+
.where(BLSession.visit_number == ExampleVisit.visit_number)
21+
)
22+
.one()
23+
.sessionId
3024
)
31-
ispyb_session.add(bl_session_db_entry)
32-
ispyb_session.commit()
3325

3426
# Test function
35-
result = get_session_id(
27+
session_id = get_session_id(
3628
microscope="murfey",
3729
proposal_code="cm",
3830
proposal_number="12345",
3931
visit_number="6",
40-
db=ispyb_session,
32+
db=ispyb_db,
4133
)
42-
assert result == bl_session_db_entry.sessionId
34+
assert result == session_id

0 commit comments

Comments
 (0)