Skip to content

Commit 2783bea

Browse files
Add test information
1 parent 33e24e6 commit 2783bea

File tree

10 files changed

+28
-26
lines changed

10 files changed

+28
-26
lines changed

infrastructure/afd-apim-pe/create.ipynb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@
187187
"from apimtesting import ApimTesting\n",
188188
"\n",
189189
"reqs = ApimRequests(apim_gateway_url)\n",
190-
"tests = ApimTesting(\"AFD-APIM-PE Tests (Pre-Lockdown)\")\n",
190+
"tests = ApimTesting(\"AFD-APIM-PE Tests (Pre-Lockdown)\", deployment, deployment)\n",
191191
"\n",
192192
"utils.print_message('Calling Hello World (Root) API via API Management Gateway URL. Expect 200 (if run before disabling API Management public network access).')\n",
193193
"output = reqs.singleGet('/')\n",
@@ -255,7 +255,7 @@
255255
"\n",
256256
"reqsApim = ApimRequests(apim_gateway_url)\n",
257257
"reqsAfd = ApimRequests(afd_endpoint_url)\n",
258-
"tests = ApimTesting(\"AFD-APIM-PE Tests (Post-Lockdown)\")\n",
258+
"tests = ApimTesting(\"AFD-APIM-PE Tests (Post-Lockdown)\", deployment, deployment)\n",
259259
"\n",
260260
"# 1) Unsuccessful call to APIM Gateway URL (should fail with 403 Forbidden)\n",
261261
"output = reqsApim.singleGet('/', msg = '1) Calling Hello World (Root) API via API Management Gateway URL. Expect 403 as APIM public access is disabled now.')\n",

infrastructure/apim-aca/create.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"from apimtesting import ApimTesting\n",
131131
"\n",
132132
"reqs = ApimRequests(apim_gateway_url)\n",
133-
"tests = ApimTesting(\"APIM-ACA Tests\")\n",
133+
"tests = ApimTesting(\"APIM-ACA Tests\", deployment, deployment)\n",
134134
"\n",
135135
"output = reqs.singleGet('/', msg = 'Calling Hello World (Root) API')\n",
136136
"tests.verify(output, 'Hello World from API Management!')\n",

infrastructure/simple-apim/create.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@
112112
"from apimtesting import ApimTesting\n",
113113
"\n",
114114
"reqs = ApimRequests(apim_gateway_url)\n",
115-
"tests = ApimTesting(\"Simple APIM Tests\")\n",
115+
"tests = ApimTesting(\"Simple APIM Tests\", deployment, deployment)\n",
116116
"\n",
117117
"output = reqs.singleGet('/', msg = 'Calling Hello World (Root) API')\n",
118118
"tests.verify(output, 'Hello World from API Management!')\n",

samples/authX-pro/create.ipynb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"outputs": [],
1919
"source": [
2020
"import utils\n",
21-
"import time\n",
2221
"from apimtypes import *\n",
2322
"\n",
2423
"# 1) User-defined parameters (change these as needed)\n",
@@ -152,7 +151,7 @@
152151
"from users import UserHelper\n",
153152
"from authfactory import AuthFactory\n",
154153
"\n",
155-
"tests = ApimTesting(\"AuthX-Pro Sample Tests\")\n",
154+
"tests = ApimTesting(\"AuthX-Pro Sample Tests\", sample_folder, deployment)\n",
156155
"\n",
157156
"# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n",
158157
"endpoint_url = utils.test_url_preflight_check(deployment, rg_name, apim_gateway_url)\n",

samples/authX/create.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@
126126
"from users import UserHelper\n",
127127
"from authfactory import AuthFactory\n",
128128
"\n",
129-
"tests = ApimTesting(\"AuthX Sample Tests\")\n",
129+
"tests = ApimTesting(\"AuthX Sample Tests\", sample_folder, deployment)\n",
130130
"\n",
131131
"# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n",
132132
"endpoint_url = utils.test_url_preflight_check(deployment, rg_name, apim_gateway_url)\n",

samples/general/create.ipynb

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,8 @@
100100
"from apimrequests import ApimRequests\n",
101101
"from apimtesting import ApimTesting\n",
102102
"\n",
103-
"tests = ApimTesting(\"General Sample Tests\")\n",
103+
"tests = ApimTesting(\"General Sample Tests\", sample_folder, deployment)\n",
104104
"\n",
105-
"# 1) Issue a direct request to API Management\n",
106-
"reqsApim = ApimRequests(apim_gateway_url)\n",
107-
"output = reqsApim.singleGet('/request-headers', msg = 'Calling Request Headers API via API Management Gateway URL. Response codes 200 and 403 are both valid depending on the infrastructure used.')\n",
108-
"tests.verify('Host:' in output, True)\n",
109-
"\n",
110-
"# 2) Issue requests against Front Door.\n",
111105
"# Check if the infrastructure architecture deployment uses Azure Front Door.\n",
112106
"utils.print_message('Checking if the infrastructure architecture deployment uses Azure Front Door.', blank_above = True)\n",
113107
"afd_endpoint_url = utils.get_frontdoor_url(deployment, rg_name)\n",
@@ -116,6 +110,10 @@
116110
" reqsAfd = ApimRequests(afd_endpoint_url)\n",
117111
" output = reqsAfd.singleGet('/request-headers', msg = 'Calling Request Headers API via via Azure Front Door. Expect 200.')\n",
118112
" tests.verify('Host:' in output, True)\n",
113+
"else:\n",
114+
" # Issue a direct request to API Management\n",
115+
" reqsApim = ApimRequests(apim_gateway_url)\n",
116+
" output = reqsApim.singleGet('/request-headers', msg = 'Calling Request Headers API via API Management Gateway URL. Response codes 200 and 403 are both valid depending on the infrastructure used.')\n",
119117
"\n",
120118
"tests.print_summary()\n",
121119
"\n",

samples/load-balancing/create.ipynb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@
116116
" utils.print_message(f'Waiting for {sleep_in_s} seconds for the backend timeouts to reset before starting the next set of calls', blank_above = True)\n",
117117
" time.sleep(sleep_in_s) # Wait a bit before the next set of calls to allow for the backend timeouts to reset\n",
118118
"\n",
119-
"tests = ApimTesting(\"Load Balancing Sample Tests\")\n",
119+
"tests = ApimTesting(\"Load Balancing Sample Tests\", sample_folder, deployment)\n",
120120
"\n",
121121
"# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door. If so, assume that APIM is not directly accessible and use the Front Door URL instead.\n",
122122
"endpoint_url = utils.test_url_preflight_check(deployment, rg_name, apim_gateway_url)\n",

samples/secure-blob-access/create.ipynb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
"outputs": [],
2121
"source": [
2222
"import utils\n",
23-
"import time\n",
2423
"from apimtypes import *\n",
2524
"\n",
2625
"# 1) User-defined parameters (change these as needed)\n",
@@ -235,7 +234,7 @@
235234
" utils.print_error(\"Failed to parse JSON response or response is not in expected format.\")\n",
236235
" return response\n",
237236
"\n",
238-
"tests = ApimTesting(\"Secure Blob Access Sample Tests\")\n",
237+
"tests = ApimTesting(\"Secure Blob Access Sample Tests\", sample_folder, deployment)\n",
239238
"\n",
240239
"# Preflight: Check if the infrastructure architecture deployment uses Azure Front Door\n",
241240
"endpoint_url = utils.test_url_preflight_check(deployment, rg_name, apim_gateway_url)\n",
@@ -244,7 +243,7 @@
244243
"utils.print_message('1) Testing with Authorized User', blank_above = True)\n",
245244
"\n",
246245
"# Create a JWT with the HR Member role (blob access)\n",
247-
"encoded_jwt_token_hr_member = AuthFactory.create_symmetric_jwt_token_for_user(UserHelper.get_user_by_role(Role.HR_MEMBER), jwt_key_value)\n",
246+
"encoded_jwt_token_hr_member = AuthFactory.create_symmetric_jwt_token_for_user(UserHelper.get_user_by_role(Role.HR_MEMBER), nb_helper.jwt_key_value)\n",
248247
"print(f'\\nJWT token for HR Member:\\n{encoded_jwt_token_hr_member}') # this value is used to call the APIs via APIM\n",
249248
"\n",
250249
"# Set up APIM requests with authorized JWT\n",
@@ -260,7 +259,7 @@
260259
"# 2) Test with unauthorized user (has blob access role)\n",
261260
"utils.print_message('2) Testing with Unauthorized User', blank_above = True)\n",
262261
"\n",
263-
"encoded_jwt_token_no_role = AuthFactory.create_symmetric_jwt_token_for_user(UserHelper.get_user_by_role(Role.NONE), jwt_key_value)\n",
262+
"encoded_jwt_token_no_role = AuthFactory.create_symmetric_jwt_token_for_user(UserHelper.get_user_by_role(Role.NONE), nb_helper.jwt_key_value)\n",
264263
"print(f'\\nJWT token for user with no role:\\n{encoded_jwt_token_no_role}') # this value is used to call the APIs via APIM\n",
265264
"\n",
266265
"# Set up APIM requests with unauthorized JWT\n",

shared/python/apimtesting.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Rudimentary test framework to offload validations from the Jupyter notebooks.
33
"""
44

5+
from apimtypes import INFRASTRUCTURE
56

67
# ------------------------------
78
# CLASSES
@@ -16,14 +17,18 @@ class ApimTesting:
1617
# CONSTRUCTOR
1718
# ------------------------------
1819

19-
def __init__(self, test_suite_name: str = 'APIM Tests') -> None:
20+
def __init__(self, test_suite_name: str = 'APIM Tests', sample_name: str = None, deployment: INFRASTRUCTURE = None) -> None:
2021
"""
2122
Initialize the ApimTesting instance.
2223
2324
Args:
2425
test_suite_name (str, optional): The name of the test suite. Defaults to 'APIM Tests'.
26+
sample_name (str, optional): The name of the sample being tested. Defaults to None.
27+
deployment (str, optional): The deployment name (INFRASTRUCTURE)
2528
"""
2629
self.test_suite_name = test_suite_name
30+
self.sample_name = sample_name
31+
self.deployment = deployment
2732
self.tests_passed = 0
2833
self.tests_failed = 0
2934
self.total_tests = 0
@@ -75,14 +80,17 @@ def print_summary(self) -> None:
7580
# Create padded title
7681
title = f"🧪 {self.test_suite_name} - Test Results Summary 🧪"
7782
title_padding = max(0, (border_width - len(title)) // 2)
78-
83+
7984
# Start the fancy display
8085
print('\n') # Blank lines for spacing
8186
print(border_line)
8287
print(f'{' ' * title_padding}{title}')
8388
print(border_line)
8489
print()
8590

91+
print(f' Sample Name : {self.sample_name if self.sample_name else "N/A"}')
92+
print(f' Deployment : {self.deployment.name if self.deployment else "N/A"}\n')
93+
8694
# Test statistics with visual indicators
8795
print(f'📊 Test Execution Statistics:')
8896
print(f' • Total Tests : {self.total_tests:>5}')
@@ -109,9 +117,7 @@ def print_summary(self) -> None:
109117
print('🔍 Detailed Error Analysis:')
110118
print('─' * 50)
111119
for i, error in enumerate(self.errors, 1):
112-
print(f'{i:>2}.\n{error}')
113-
else:
114-
print('✅ No errors encountered - Everything looks great!')
120+
print(f'{i:>2}. {error}\n')
115121

116122
print()
117123
print(border_line)

shared/python/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -921,7 +921,7 @@ def get_frontdoor_url(deployment_name: INFRASTRUCTURE, rg_name: str) -> str | No
921921
if afd_endpoint_url:
922922
print_ok(f"Front Door Endpoint URL: {afd_endpoint_url}", blank_above = False)
923923
else:
924-
print_error("No Front Door endpoint URL found. Please check the deployment and ensure that Azure Front Door is configured correctly.")
924+
print_warning("No Front Door endpoint URL found.")
925925

926926
return afd_endpoint_url
927927

@@ -1288,7 +1288,7 @@ def cleanup_old_jwt_signing_keys(apim_name: str, resource_group_name: str, curre
12881288
deleted_count += 1
12891289

12901290
# Summary
1291-
print_success(f"JWT signing key cleanup completed. Deleted {deleted_count} old keys, kept {kept_count}'.", blank_above = True)
1291+
print_success(f"JWT signing key cleanup completed. Deleted {deleted_count} old key(s), kept {kept_count}'.", blank_above = True)
12921292
return True
12931293

12941294
except Exception as e:

0 commit comments

Comments
 (0)