Skip to content

Commit ebb9ea6

Browse files
authored
Allow shipping service backend/frontend URLs to be set separately (#3)
* Allow shipping service backend/frontend URLs to be set separately * Linting
1 parent 15913bc commit ebb9ea6

File tree

7 files changed

+22
-18
lines changed

7 files changed

+22
-18
lines changed

config.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"read_all_perms": ["super_admin"]
77
},
88
"shipping_service": {
9-
"url": "https://sample-shipping-staging.diamond.ac.uk"
9+
"backend_url": "https://sample-shipping-staging.diamond.ac.uk",
10+
"frontend_url": "https://sample-shipping-staging.diamond.ac.uk"
1011
},
1112
"db": { "pool": 3, "overflow": 6 },
1213
"ispyb_api": "http://127.0.0.1:8060/api",

src/scaup/crud/pdf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def __call__(self, shipment_id: int, token: str):
7777
return self._consignee_cache
7878

7979
consignee_response = ExternalRequest.request(
80-
base_url=Config.shipping_service.url,
80+
base_url=Config.shipping_service.backend_url,
8181
token=token,
8282
method="GET",
8383
url=f"/api/shipments/{shipment_id}",
@@ -291,7 +291,7 @@ def get_shipping_labels(shipment_id: int, token: str):
291291

292292
if data[0].shipmentRequest is not None:
293293
response = ExternalRequest.request(
294-
base_url=Config.shipping_service.url,
294+
base_url=Config.shipping_service.backend_url,
295295
token=token,
296296
method="GET",
297297
url=f"/api/shipment_requests/{data[0].shipmentRequest}/shipments/TO_FACILITY",

src/scaup/crud/shipments.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ def build_shipment_request(shipmentId: int, token: str):
228228
}
229229

230230
response = ExternalRequest.request(
231-
base_url=Config.shipping_service.url,
231+
base_url=Config.shipping_service.backend_url,
232232
token=token,
233233
method="POST",
234234
url="/api/shipment_requests/",
@@ -265,7 +265,7 @@ def get_shipment_request(shipmentId: int):
265265
"Shipment does not have a request assigned to it",
266266
)
267267

268-
return f"{Config.shipping_service.url}/shipment-requests/{request_id}/incoming"
268+
return f"{Config.shipping_service.frontend_url}/shipment-requests/{request_id}/incoming"
269269

270270

271271
def handle_callback(shipment_id: int, callback_body: StatusUpdate):

src/scaup/utils/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ class DB:
3333

3434
@dataclass
3535
class ShippingService:
36-
url: str = "https://localtest.diamond.ac.uk/"
36+
frontend_url: str = "https://localtest.diamond.ac.uk/"
37+
backend_url: str = "https://localtest.diamond.ac.uk/"
3738
secret: str = "no-secret"
3839
callback_url: str = "https://localhost/api"
3940

tests/shipments/test_create_request.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
def test_create_shipment_request(client):
1818
"""Should create shipment request in external application"""
1919
responses.post(
20-
f"{Config.shipping_service.url}/api/shipment_requests/",
20+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
2121
status=201,
2222
json={"shipmentRequestId": 50},
2323
)
@@ -38,7 +38,7 @@ def test_create_shipment_request(client):
3838
def test_shipment_request_body(client):
3939
"""Should send well formed body to upstream service"""
4040
resp_post = responses.post(
41-
f"{Config.shipping_service.url}/api/shipment_requests/",
41+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
4242
status=201,
4343
json={"shipmentRequestId": 50},
4444
)
@@ -65,7 +65,7 @@ def test_shipment_request_body(client):
6565
def test_shipment_request_callback(client):
6666
"""Should send callback URL to shipping service"""
6767
resp_post = responses.post(
68-
f"{Config.shipping_service.url}/api/shipment_requests/",
68+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
6969
status=201,
7070
json={"shipmentRequestId": 50},
7171
)
@@ -94,7 +94,7 @@ def test_shipment_request_callback(client):
9494
def test_shipment_request_item_not_registered(client):
9595
"""Should use long definition for items if item type is not registered"""
9696
resp_post = responses.post(
97-
f"{Config.shipping_service.url}/api/shipment_requests/",
97+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
9898
status=201,
9999
json={"shipmentRequestId": 50},
100100
)
@@ -123,7 +123,7 @@ def test_shipment_request_item_not_registered(client):
123123
def test_shipment_request_tlc_not_registered(client):
124124
"""Should use placeholder dimensions if top level container type is not registered"""
125125
resp_post = responses.post(
126-
f"{Config.shipping_service.url}/api/shipment_requests/",
126+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
127127
status=201,
128128
json={"shipmentRequestId": 50},
129129
)
@@ -177,7 +177,7 @@ def test_unassigned(client):
177177
def test_request_fail(client):
178178
"""Should not create shipment request if upstream application returns error"""
179179
responses.post(
180-
f"{Config.shipping_service.url}/api/shipment_requests/",
180+
f"{Config.shipping_service.backend_url}/api/shipment_requests/",
181181
status=404,
182182
)
183183

tests/shipments/test_get_request.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ def test_get(client):
66
resp = client.get("/shipments/117/request", follow_redirects=False)
77

88
assert resp.status_code == 307
9-
assert resp.headers["location"] == f"{Config.shipping_service.url}/shipment-requests/1/incoming"
9+
assert resp.headers["location"] == f"{Config.shipping_service.frontend_url}/shipment-requests/1/incoming"
1010

1111

1212
def test_get_no_id(client):

tests/shipments/test_tracking_labels.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
@responses.activate
1010
def test_get(client):
1111
"""Should get tracking labels as a PDF"""
12-
responses.get(f"{Config.shipping_service.url}/api/shipment_requests/1/shipments/TO_FACILITY", status=404)
12+
responses.get(f"{Config.shipping_service.backend_url}/api/shipment_requests/1/shipments/TO_FACILITY", status=404)
1313

1414
resp = client.get("/shipments/117/tracking-labels")
1515

@@ -36,10 +36,11 @@ def test_no_top_level_containers(client):
3636
def test_user_address(client):
3737
"""Should return include to/from address if these are available"""
3838
responses.get(
39-
f"{Config.shipping_service.url}/api/shipment_requests/1/shipments/TO_FACILITY", json=SHIPMENT_REQUEST_CONTENTS
39+
f"{Config.shipping_service.backend_url}/api/shipment_requests/1/shipments/TO_FACILITY",
40+
json=SHIPMENT_REQUEST_CONTENTS,
4041
)
4142

42-
responses.get(f"{Config.shipping_service.url}/api/shipments/1", json=SHIPMENT_CONTENTS, status=200)
43+
responses.get(f"{Config.shipping_service.backend_url}/api/shipments/1", json=SHIPMENT_CONTENTS, status=200)
4344

4445
resp = client.get("/shipments/117/tracking-labels")
4546

@@ -50,10 +51,11 @@ def test_user_address(client):
5051
def test_user_address_no_consignee(client):
5152
"""Should raise exception if shipment service returns 'from' address but no 'to' address"""
5253
responses.get(
53-
f"{Config.shipping_service.url}/api/shipment_requests/1/shipments/TO_FACILITY", json=SHIPMENT_REQUEST_CONTENTS
54+
f"{Config.shipping_service.backend_url}/api/shipment_requests/1/shipments/TO_FACILITY",
55+
json=SHIPMENT_REQUEST_CONTENTS,
5456
)
5557

56-
responses.get(f"{Config.shipping_service.url}/api/shipments/1", status=404)
58+
responses.get(f"{Config.shipping_service.backend_url}/api/shipments/1", status=404)
5759

5860
resp = client.get("/shipments/117/tracking-labels")
5961

0 commit comments

Comments
 (0)