Skip to content

Commit 561b833

Browse files
author
Francisco Videira
committed
refactor sandbox url
1 parent eba07c6 commit 561b833

File tree

4 files changed

+26
-55
lines changed

4 files changed

+26
-55
lines changed

sandbox/src/app.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@ const addCommonHeaders = function (request, response) {
1414
response.headers = {}
1515
}
1616

17+
// API proxy always adds x-correlation-id to responses.
18+
if (request.headers["x-correlation-id"]) {
19+
response.headers["X-Correlation-ID"] = request.headers["x-correlation-id"]
20+
}
21+
1722
if (!request.path.includes("/ObjectStore")) {
18-
if (request.headers["x-correlation-id"]) {
19-
response.headers["X-Correlation-ID"] = request.headers["x-correlation-id"]
20-
}
2123
response.headers["X-Request-ID"] = '58621d65-d5ad-4c3a-959f-0438e355990e-1'
2224
}
2325
}

tests/sandbox/conftest.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,30 @@ def load_file(environment) -> Callable[[str], bytes]:
3838

3939
@pytest.fixture
4040
def send_rest_request(
41-
sandbox_url,
41+
sandbox_url, environment
4242
) -> Callable[[HttpMethod, str, Actor], requests.Response]:
4343
"""Provides a method which encapsulates the logic of sending a REST call to the correct base URL"""
4444
return lambda method, url, actor, headers={}, **kwargs: _send_rest_request(
45-
method, sandbox_url + "/" + url, actor, headers, **kwargs
45+
method,
46+
sandbox_url + "/" + url,
47+
_process_headers(headers, environment, actor, sandbox_url),
48+
**kwargs
4649
)
4750

4851

52+
def _process_headers(
53+
headers: Dict[str, str], environment: str, actor: Actor, sandbox_url: str
54+
) -> Dict[str, str]:
55+
if environment == "local":
56+
headers.update({"x-ers-sandbox-baseurl": sandbox_url})
57+
58+
headers[RenamedHeader.BUSINESS_FUNCTION.original] = actor.business_function
59+
if actor.obo_user_id != None:
60+
headers[RenamedHeader.OBO_USER_ID.original] = actor.obo_user_id
61+
62+
return headers
63+
64+
4965
def _get_json(base_path: str, path: str) -> Dict[str, str]:
5066
with open(base_path + path) as f:
5167
return json.load(f)
@@ -57,9 +73,6 @@ def _get_file(base_path: str, path: str) -> bytes:
5773

5874

5975
def _send_rest_request(
60-
method: HttpMethod, url: str, actor: Actor, headers: Dict[str, str], **kwargs
76+
method: HttpMethod, url: str, headers: Dict[str, str], **kwargs
6177
) -> requests.Response:
62-
headers[RenamedHeader.BUSINESS_FUNCTION.original] = actor.business_function
63-
if actor.obo_user_id != None:
64-
headers[RenamedHeader.OBO_USER_ID.original] = actor.obo_user_id
6578
return method(url, headers=headers, **kwargs)

tests/sandbox/r4/test_a042_get_attachment.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,8 @@ def test_success(
6161
actor: Actor,
6262
id: str,
6363
sandbox_url: str,
64-
environment: str,
6564
):
66-
request_headers = (
67-
{"x-ers-sandbox-baseurl": sandbox_url} if environment == "local" else {}
68-
)
69-
70-
actual_response = call_endpoint_url_with_pathParams(
71-
actor, {"binaryId": id}, request_headers
72-
)
65+
actual_response = call_endpoint_url_with_pathParams(actor, {"binaryId": id})
7366

7467
asserts.assert_status_code(307, actual_response.status_code)
7568

tests/sandbox/r4/test_a042_get_attachment_follow_redirection.py

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,9 @@ def test_success(
6666
],
6767
actor: Actor,
6868
id: str,
69-
sandbox_url: str,
70-
environment: str,
7169
):
72-
request_headers = (
73-
{"x-ers-sandbox-baseurl": sandbox_url} if environment == "local" else {}
74-
)
75-
7670
actual_response = call_endpoint_url_with_pathParams(
77-
actor, {"binaryId": id}, request_headers, allow_redirects=True
71+
actor, {"binaryId": id}, allow_redirects=True
7872
)
7973

8074
asserts.assert_status_code(200, actual_response.status_code)
@@ -96,34 +90,3 @@ def test_success(
9690
assert_content_length=True,
9791
assert_ignored_headers=False,
9892
)
99-
100-
def test_with_correlation_id(
101-
self,
102-
call_endpoint: Callable[[Actor], Response],
103-
authorised_actors: Iterable[Actor],
104-
default_headers: Dict[str, str],
105-
sandbox_url: str,
106-
environment: str,
107-
):
108-
"""
109-
Overrides parent test. It's expected that following the redirection will result in a response from the object store without a correlation id.
110-
"""
111-
request_headers = {RenamedHeader.CORRELATION_ID.original: "test"}
112-
113-
if environment == "local":
114-
request_headers["x-ers-sandbox-baseurl"] = sandbox_url
115-
116-
response = call_endpoint(
117-
authorised_actors[0],
118-
headers=request_headers,
119-
)
120-
121-
# Check that the response completed successfully.
122-
assert (
123-
response.status_code // 200 == 1
124-
), "Supplied request did not complete successfully."
125-
126-
with check:
127-
assert (
128-
RenamedHeader.CORRELATION_ID.original not in response.headers
129-
), "Object store expected not to return a correlation id."

0 commit comments

Comments
 (0)