Skip to content

Commit b935736

Browse files
authored
Display PDF even if beamline operator is missing (#9)
1 parent f9ba469 commit b935736

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

src/scaup/crud/pdf.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,20 +110,24 @@ class TrackingLabelPages(FPDF):
110110
def __init__(
111111
self,
112112
location: str,
113-
local_contact: str,
113+
local_contact: str | None,
114114
from_lines: List[str] | None = None,
115115
to_lines: List[str] | None = None,
116116
):
117117
super().__init__()
118118
self.set_font("helvetica", size=14)
119119
self.location = location
120-
self.local_contact = local_contact
121120
self.from_lines = from_lines
122121
self.to_lines = to_lines
123122

124-
# Only display two first local contacts, to save space
125-
if len(lcs := local_contact.split(",")) > 2:
126-
self.local_contact = f"{', '.join(lcs[:2])} + {len(lcs) - 2}"
123+
if not local_contact:
124+
self.local_contact = "Unknown"
125+
else:
126+
# Only display two first local contacts, to save space
127+
if len(lcs := local_contact.split(",")) > 2:
128+
self.local_contact = f"{', '.join(lcs[:2])} + {len(lcs) - 2}"
129+
else:
130+
self.local_contact = local_contact
127131

128132
self.add_page()
129133

tests/shipments/test_tracking_labels.py

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1+
import pytest
12
import responses
23

34
from scaup.utils.config import Config
45

56
SHIPMENT_REQUEST_CONTENTS = {"shipmentId": 1, "contact": {"a": "b", "c": "d"}}
6-
SHIPMENT_CONTENTS = {"consignee_address_line_1": "test", "consignee_email": "test@diamond.ac.uk"}
7+
SHIPMENT_CONTENTS = {
8+
"consignee_address_line_1": "test",
9+
"consignee_email": "test@diamond.ac.uk",
10+
}
711

812

913
@responses.activate
1014
def test_get(client):
1115
"""Should get tracking labels as a PDF"""
12-
responses.get(f"{Config.shipping_service.backend_url}/api/shipment_requests/1/shipments/TO_FACILITY", status=404)
16+
responses.get(
17+
f"{Config.shipping_service.backend_url}/api/shipment_requests/1/shipments/TO_FACILITY",
18+
status=404,
19+
)
1320

1421
resp = client.get("/shipments/117/tracking-labels")
1522

@@ -32,6 +39,19 @@ def test_no_top_level_containers(client):
3239
assert resp.status_code == 404
3340

3441

42+
@pytest.mark.noregister
43+
@responses.activate
44+
def test_no_beamline_operator(client):
45+
"""Should return 200 even if beamline operator is missing"""
46+
responses.get(
47+
f"{Config.ispyb_api.url}/proposals/cm1/sessions/1",
48+
json={"items": [{"beamLineName": "m01", "beamLineOperator": None}]},
49+
)
50+
resp = client.get("/shipments/118/tracking-labels")
51+
52+
assert resp.status_code == 404
53+
54+
3555
@responses.activate
3656
def test_user_address(client):
3757
"""Should return include to/from address if these are available"""
@@ -40,7 +60,11 @@ def test_user_address(client):
4060
json=SHIPMENT_REQUEST_CONTENTS,
4161
)
4262

43-
responses.get(f"{Config.shipping_service.backend_url}/api/shipments/1", json=SHIPMENT_CONTENTS, status=200)
63+
responses.get(
64+
f"{Config.shipping_service.backend_url}/api/shipments/1",
65+
json=SHIPMENT_CONTENTS,
66+
status=200,
67+
)
4468

4569
resp = client.get("/shipments/117/tracking-labels")
4670

0 commit comments

Comments
 (0)