Skip to content

Commit bf66bd1

Browse files
committed
Return none when pre-session info does not exist
1 parent 9184fd1 commit bf66bd1

File tree

3 files changed

+19
-11
lines changed

3 files changed

+19
-11
lines changed

src/scaup/crud/pre_sessions.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
from fastapi import HTTPException, status
21
from fastapi.security import HTTPAuthorizationCredentials
32
from lims_utils.auth import GenericUser
43
from sqlalchemy import select
@@ -26,13 +25,10 @@ def create_pre_session_info(shipmentId: int, params: PreSessionIn):
2625

2726
def get_pre_session_info(shipment_id: int, user: GenericUser, token: HTTPAuthorizationCredentials):
2827
pre_session_info = inner_db.session.scalar(select(PreSession).filter(PreSession.shipmentId == shipment_id))
29-
if not pre_session_info:
30-
raise HTTPException(
31-
status.HTTP_404_NOT_FOUND,
32-
"Shipment does not have a request assigned to it",
33-
)
34-
35-
validated_model = PreSessionOut.model_validate(pre_session_info, from_attributes=True)
36-
validated_model.isLocked = check_session_locked(shipment_id, user, token)
28+
29+
validated_model = PreSessionOut(
30+
details=None if pre_session_info is None else pre_session_info.details,
31+
isLocked=check_session_locked(shipment_id, user, token),
32+
)
3733

3834
return validated_model

src/scaup/models/pre_sessions.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55

66
class BasePreSession(BaseModel):
77
details: Optional[dict[str, Any]] = None
8-
isLocked: bool = False
98

109

1110
class PreSessionIn(BasePreSession):
@@ -17,4 +16,4 @@ class PreSessionOptional(BasePreSession):
1716

1817

1918
class PreSessionOut(BasePreSession):
20-
pass
19+
isLocked: bool = False

tests/shipments/pre_session/test_get.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ def test_get(mock_user, client):
1818
assert resp.json() == {"details": {"name": "previous"}, "isLocked": False}
1919

2020

21+
@freeze_time("2025-07-01T15:00:00")
22+
@responses.activate
23+
@pytest.mark.parametrize("mock_user", [user], indirect=True)
24+
def test_get_no_pre_session(mock_user, client):
25+
"""Should return null if no pre session information is available"""
26+
27+
resp = client.get("/shipments/1/preSession")
28+
29+
assert resp.status_code == 200
30+
31+
assert resp.json() == {"details": None, "isLocked": False}
32+
33+
2134
@freeze_time("2025-07-20T15:00:00")
2235
@responses.activate
2336
@pytest.mark.parametrize("mock_user", [user], indirect=True)

0 commit comments

Comments
 (0)