|
1 | | -from ispyb.sqlalchemy import BLSession, Person, Proposal |
| 1 | +from ispyb.sqlalchemy import BLSession, Proposal |
| 2 | +from sqlmodel import Session, select |
2 | 3 |
|
3 | 4 | from murfey.server.ispyb import get_session_id |
| 5 | +from tests.conftest import ExampleVisit |
4 | 6 |
|
5 | 7 |
|
6 | 8 | def test_get_session_id( |
7 | | - ispyb_session, |
| 9 | + ispyb_db: Session, |
8 | 10 | ): |
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 |
30 | 24 | ) |
31 | | - ispyb_session.add(bl_session_db_entry) |
32 | | - ispyb_session.commit() |
33 | 25 |
|
34 | 26 | # Test function |
35 | | - result = get_session_id( |
| 27 | + session_id = get_session_id( |
36 | 28 | microscope="murfey", |
37 | 29 | proposal_code="cm", |
38 | 30 | proposal_number="12345", |
39 | 31 | visit_number="6", |
40 | | - db=ispyb_session, |
| 32 | + db=ispyb_db, |
41 | 33 | ) |
42 | | - assert result == bl_session_db_entry.sessionId |
| 34 | + assert result == session_id |
0 commit comments