Skip to content

Commit e6cab9f

Browse files
Merge pull request #12 from NHSDigital/AMB-643-add-test-coverage-using-apigee-debug-api
Amb 643 add test coverage using apigee debug api
2 parents f9b1547 + d4cb1a3 commit e6cab9f

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

tests/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ pyjwt
66
python-dotenv
77
assertpy
88
pytest-rerunfailures
9-
https://github.com/NHSDigital/apim-test-utils/releases/download/v1.0.86-alpha/api_test_utils-1.0.86a0-py3-none-any.whl
9+
https://github.com/NHSDigital/apim-test-utils/releases/download/v1.1.6-alpha/api_test_utils-1.1.6a0-py3-none-any.whl

tests/test_endpoints.py

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from api_test_utils.oauth_helper import OauthHelper
77
from api_test_utils.apigee_api_apps import ApigeeApiDeveloperApps
88
from api_test_utils.apigee_api_products import ApigeeApiProducts
9+
from api_test_utils.apigee_api_trace import ApigeeApiTraceDebug
910

1011

1112
class TestEndpoints:
@@ -34,6 +35,14 @@ def product(self):
3435
"""
3536
return ApigeeApiProducts()
3637

38+
@pytest.fixture()
39+
def debug(self):
40+
"""
41+
Import the test utils module to be able to:
42+
- Use the trace tool and get context variables after making a request to Apigee
43+
"""
44+
return ApigeeApiTraceDebug(proxy='shared-flow-testing-internal-dev')
45+
3746
@pytest.fixture()
3847
async def test_app_and_product(self, app, product):
3948
"""Create a test app and product which can be modified in the test"""
@@ -183,12 +192,13 @@ async def test_default_role(self, get_token):
183192
assert_that(expected_status_code).is_equal_to(response.status_code)
184193

185194
@pytest.mark.asyncio
186-
async def test_user_invalid_role_in_header(self, get_token):
195+
async def test_user_invalid_role_in_header(self, get_token, debug):
187196
# Given
188197
token = get_token["access_token"]
189198
expected_status_code = 400
190199
expected_error = "Bad Request"
191200
expected_error_description = "nhsd-session-urid is invalid"
201+
await debug.start_trace()
192202

193203
# When
194204
response = requests.get(
@@ -198,46 +208,54 @@ async def test_user_invalid_role_in_header(self, get_token):
198208
"NHSD-Session-URID": "notAuserRole123",
199209
},
200210
)
211+
isSharedFlowError = await debug.get_apigee_variable_from_trace(name='isSharedFlowError')
201212

202213
# Then
214+
assert_that(isSharedFlowError).is_equal_to('true')
203215
assert_that(expected_status_code).is_equal_to(response.status_code)
204216
assert_that(expected_error).is_equal_to(response.json()["issue"][0]["details"]["coding"][0]["display"])
205217
assert_that(expected_error_description).is_equal_to(response.json()["issue"][0]["diagnostics"])
206218

207219
@pytest.mark.asyncio
208-
async def test_no_role_provided(self, get_token_client_credentials):
220+
async def test_no_role_provided(self, get_token_client_credentials, debug):
209221
token = get_token_client_credentials["access_token"]
210222
# Given
211223
expected_status_code = 400
212224
expected_error = "Bad Request"
213225
expected_error_description = "selected_roleid is missing in your token"
226+
await debug.start_trace()
214227

215228
# When
216229
response = requests.get(
217230
url="https://internal-dev.api.service.nhs.uk/shared-flow-testing/user-role-service",
218231
headers={"Authorization": f"Bearer {token}"},
219232
)
233+
isSharedFlowError = await debug.get_apigee_variable_from_trace(name='isSharedFlowError')
220234
# Then
235+
assert_that(isSharedFlowError).is_equal_to('true')
221236
assert_that(expected_status_code).is_equal_to(response.status_code)
222237
assert_that(expected_error).is_equal_to(response.json()["issue"][0]["details"]["coding"][0]["display"])
223238
assert_that(expected_error_description).is_equal_to(response.json()["issue"][0]["diagnostics"])
224239

225240
@pytest.mark.asyncio
226241
async def test_nhs_login_exchanged_token_no_role_provided(
227-
self, get_token_nhs_login_token_exchange
242+
self, get_token_nhs_login_token_exchange, debug
228243
):
229244
token = get_token_nhs_login_token_exchange["access_token"]
230245
# Given
231246
expected_status_code = 400
232247
expected_error = "Bad Request"
233248
expected_error_description = "selected_roleid is missing in your token"
249+
await debug.start_trace()
234250

235251
# When
236252
response = requests.get(
237253
url="https://internal-dev.api.service.nhs.uk/shared-flow-testing/user-role-service",
238254
headers={"Authorization": f"Bearer {token}"},
239255
)
256+
isSharedFlowError = await debug.get_apigee_variable_from_trace(name='isSharedFlowError')
240257
# Then
258+
assert_that(isSharedFlowError).is_equal_to('true')
241259
assert_that(expected_status_code).is_equal_to(response.status_code)
242260
assert_that(expected_error).is_equal_to(response.json()["issue"][0]["details"]["coding"][0]["display"])
243261
assert_that(expected_error_description).is_equal_to(response.json()["issue"][0]["diagnostics"])

0 commit comments

Comments
 (0)