Skip to content

Commit 2486970

Browse files
change approach with apim_app_flow_vars injection
1 parent baa0bf9 commit 2486970

File tree

2 files changed

+47
-45
lines changed

2 files changed

+47
-45
lines changed

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,8 @@ async def _make_app(product, custom_attributes={}):
342342

343343
@pytest.fixture
344344
def authenticate_user(client, user_restricted_app, environment, oauth_url):
345-
async def _auth(actor: Actor, apim_app_flow_vars=None):
345+
async def _auth(actor: Actor):
346346
print(f"Attempting to authenticate: {actor}")
347-
if apim_app_flow_vars is not None:
348-
print(f"Using apim_app_flow_vars: {apim_app_flow_vars}")
349347

350348
credentials = user_restricted_app["credentials"][0]
351349

tests/integration/test_user_restricted.py

Lines changed: 46 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -74,45 +74,49 @@ async def test_user_restricted_valid_ods_code(
7474
response.status_code == 200
7575
), "Expected a 200 when accessing the api but got " + str(response.status_code)
7676

77-
# TODO: Pick up as part of follow-up ODS technical debt work
78-
# @pytest.mark.asyncio
79-
# @pytest.mark.parametrize(
80-
# "endpoint_url, is_fhir_4",
81-
# [("", False), ("/FHIR/R4/", True), ("/FHIR/STU3/", False)],
82-
# )
83-
# async def test_user_restricted_invalid_ods_code(
84-
# self,
85-
# authenticate_user,
86-
# endpoint_url,
87-
# referring_clinician,
88-
# is_fhir_4,
89-
# service_url,
90-
# update_user_restricted_product,
91-
# ):
92-
# access_code = await authenticate_user(referring_clinician, ["invalid_code"])
93-
#
94-
# client_request_headers = {
95-
# _HEADER_ECHO: "", # enable echo target
96-
# _HEADER_AUTHORIZATION: "Bearer " + access_code,
97-
# _HEADER_REQUEST_ID: "DUMMY-VALUE",
98-
# RenamedHeader.REFERRAL_ID.original: _EXPECTED_REFERRAL_ID,
99-
# RenamedHeader.CORRELATION_ID.original: _EXPECTED_CORRELATION_ID,
100-
# RenamedHeader.BUSINESS_FUNCTION.original: referring_clinician.business_function,
101-
# RenamedHeader.ODS_CODE.original: referring_clinician.org_code,
102-
# RenamedHeader.FILENAME.original: _EXPECTED_FILENAME,
103-
# RenamedHeader.COMM_RULE_ORG.original: _EXPECTED_COMM_RULE_ORG,
104-
# RenamedHeader.OBO_USER_ID.original: _EXPECTED_OBO_USER_ID,
105-
# }
106-
#
107-
# # Make the API call
108-
#
109-
# # Make request with user with ODS code not in allow list (e.g. R69)
110-
# response = requests.get(
111-
# f"{service_url}{endpoint_url}", headers=client_request_headers
112-
# )
113-
#
114-
# # Verify the status
115-
# # Verify 403 response with appropriate error message
116-
# assert (
117-
# response.status_code == 403
118-
# ), "Expected a 403 when accessing the api but got " + str(response.status_code)
77+
@pytest.mark.asyncio
78+
@pytest.mark.parametrize(
79+
"endpoint_url, is_fhir_4, apim_app_flow_vars",
80+
[
81+
("", False, ["invalid_code"]),
82+
("/FHIR/R4/", True, ["invalid_code"]),
83+
("/FHIR/STU3/", False, ["invalid_code"]),
84+
],
85+
)
86+
async def test_user_restricted_invalid_ods_code(
87+
self,
88+
authenticate_user,
89+
endpoint_url,
90+
referring_clinician,
91+
is_fhir_4,
92+
service_url,
93+
apim_app_flow_vars,
94+
update_user_restricted_product,
95+
):
96+
access_code = await authenticate_user(referring_clinician)
97+
98+
client_request_headers = {
99+
_HEADER_ECHO: "", # enable echo target
100+
_HEADER_AUTHORIZATION: "Bearer " + access_code,
101+
_HEADER_REQUEST_ID: "DUMMY-VALUE",
102+
RenamedHeader.REFERRAL_ID.original: _EXPECTED_REFERRAL_ID,
103+
RenamedHeader.CORRELATION_ID.original: _EXPECTED_CORRELATION_ID,
104+
RenamedHeader.BUSINESS_FUNCTION.original: referring_clinician.business_function,
105+
RenamedHeader.ODS_CODE.original: referring_clinician.org_code,
106+
RenamedHeader.FILENAME.original: _EXPECTED_FILENAME,
107+
RenamedHeader.COMM_RULE_ORG.original: _EXPECTED_COMM_RULE_ORG,
108+
RenamedHeader.OBO_USER_ID.original: _EXPECTED_OBO_USER_ID,
109+
}
110+
111+
# Make the API call
112+
113+
# Make request with user with ODS code not in allow list (e.g. R69)
114+
response = requests.get(
115+
f"{service_url}{endpoint_url}", headers=client_request_headers
116+
)
117+
118+
# Verify the status
119+
# Verify 403 response with appropriate error message
120+
assert (
121+
response.status_code == 403
122+
), "Expected a 403 when accessing the api but got " + str(response.status_code)

0 commit comments

Comments
 (0)