Skip to content

Commit 867b1d3

Browse files
Merge pull request #1820 from NHSDigital/feature/ERSSUP-80635
[ERSSUP-80635]-[]-[Check for body in 403 response]-[DMW]
2 parents 3218bc2 + 02a6a30 commit 867b1d3

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

tests/asserts.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,28 @@ def assert_error_response(
225225

226226
for renamed_header in RenamedHeader:
227227
assert renamed_header.renamed not in client_response_headers
228+
229+
230+
def assert_error_response_with_body(
231+
response: Response, expected_correlation_id: int, expected_status_code: int
232+
):
233+
# Verify the status
234+
assert response.status_code == expected_status_code, (
235+
"Expected a "
236+
+ expected_status_code
237+
+ " when accessing the api but got "
238+
+ (str)(response.status_code)
239+
)
240+
241+
assert len(response.content) > 0
242+
243+
# Verify the response headers
244+
client_response_headers = response.headers
245+
246+
assert (
247+
client_response_headers[RenamedHeader.CORRELATION_ID.original]
248+
== expected_correlation_id
249+
)
250+
251+
for renamed_header in RenamedHeader:
252+
assert renamed_header.renamed not in client_response_headers

tests/integration/test_app_restricted.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
import requests
33
from requests import Response
44
from tests.data import RenamedHeader
5-
from tests.asserts import assert_ok_response, assert_error_response
5+
from tests.asserts import (
6+
assert_ok_response,
7+
assert_error_response,
8+
assert_error_response_with_body,
9+
)
610

711
_HEADER_AUTHORIZATION = "Authorization"
812
_HEADER_ECHO = "echo" # enable echo target
@@ -42,7 +46,7 @@ async def test_authorised_application_not_supported_for_user_restricted(
4246
f"{service_url}{_SPECIALTY_REF_DATA_URL}", headers=client_request_headers
4347
)
4448

45-
assert_error_response(response, _EXPECTED_CORRELATION_ID, 403)
49+
assert_error_response_with_body(response, _EXPECTED_CORRELATION_ID, 403)
4650

4751
def test_authorised_application_supported_for_app_restricted(
4852
self, app_restricted_access_code, service_url

0 commit comments

Comments
 (0)