Skip to content

Commit 6da962c

Browse files
Initial check in of refactored tests
1 parent fe1b961 commit 6da962c

File tree

7 files changed

+1508
-1776
lines changed

7 files changed

+1508
-1776
lines changed

tests/Test-Matrix.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
**Date / time**: __________________
44

5-
| Sample / Infrastructure | SIMPLE APIM | APIM ACA | AFD APIM PE | App Gateway APIM ACA |
6-
|:----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|
7-
| **INFRASTRUCTURE** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
8-
| **authX** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
9-
| **authX-pro** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
10-
| **azure-maps** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
11-
| **general** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
12-
| **load-balancing** | **N/A** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
13-
| **oauth-3rd-party** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
14-
| **secure-blob-access** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
15-
| **INFRASTRUCTURE clean-up** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
5+
| Sample / Infrastructure | SIMPLE APIM | APIM ACA | AFD APIM PE | App Gateway APIM ACA | App Gateway APIM PE |
6+
|:----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|
7+
| **INFRASTRUCTURE** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
8+
| **authX** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
9+
| **authX-pro** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
10+
| **azure-maps** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
11+
| **general** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
12+
| **load-balancing** | **N/A** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
13+
| **oauth-3rd-party** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
14+
| **secure-blob-access** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
15+
| **INFRASTRUCTURE clean-up** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |

tests/python/conftest.py

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,21 @@
1010
# Add the shared/python directory to the Python path for all tests
1111
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../shared/python')))
1212

13+
# Add the tests/python directory to import test_helpers
14+
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))
15+
16+
# APIM Samples imports
17+
# pylint: disable=wrong-import-position
18+
from test_helpers import (
19+
create_mock_http_response,
20+
create_mock_output,
21+
create_sample_apis,
22+
create_sample_policy_fragments,
23+
get_sample_infrastructure_params,
24+
MockApimRequestsPatches,
25+
MockInfrastructuresPatches
26+
)
27+
1328

1429
# ------------------------------
1530
# SHARED FIXTURES
@@ -34,3 +49,81 @@ def sample_test_data() -> dict[str, Any]:
3449
'test_resource_group': 'rg-test-apim-01',
3550
'test_location': 'eastus2'
3651
}
52+
53+
54+
# ------------------------------
55+
# MOCK FIXTURES
56+
# ------------------------------
57+
58+
@pytest.fixture(autouse=True)
59+
def infrastructures_patches():
60+
"""Automatically patch infrastructures dependencies for tests."""
61+
with MockInfrastructuresPatches() as patches:
62+
yield patches
63+
64+
65+
@pytest.fixture
66+
def mock_utils(infrastructures_patches):
67+
"""Return the patched utils module for infrastructures tests."""
68+
return infrastructures_patches.utils
69+
70+
71+
@pytest.fixture
72+
def mock_az(infrastructures_patches):
73+
"""Return the patched azure_resources module for infrastructures tests."""
74+
return infrastructures_patches.az
75+
76+
77+
@pytest.fixture
78+
def mock_az_success():
79+
"""Pre-configured successful Azure CLI output."""
80+
return create_mock_output(success=True, json_data={'result': 'success'})
81+
82+
83+
@pytest.fixture
84+
def mock_az_failure():
85+
"""Pre-configured failed Azure CLI output."""
86+
return create_mock_output(success=False, text='Error message')
87+
88+
89+
@pytest.fixture
90+
def sample_policy_fragments():
91+
"""Provide sample policy fragments for testing."""
92+
return create_sample_policy_fragments(count=2)
93+
94+
95+
@pytest.fixture
96+
def sample_apis():
97+
"""Provide sample APIs for testing."""
98+
return create_sample_apis(count=2)
99+
100+
101+
@pytest.fixture
102+
def sample_infrastructure_params() -> dict[str, Any]:
103+
"""Provide common infrastructure parameters."""
104+
return get_sample_infrastructure_params()
105+
106+
107+
@pytest.fixture
108+
def mock_http_response_200():
109+
"""Pre-configured successful HTTP response."""
110+
return create_mock_http_response(
111+
status_code=200,
112+
json_data={'result': 'ok'}
113+
)
114+
115+
116+
@pytest.fixture
117+
def mock_http_response_error():
118+
"""Pre-configured error HTTP response."""
119+
return create_mock_http_response(
120+
status_code=500,
121+
text='Internal Server Error'
122+
)
123+
124+
125+
@pytest.fixture
126+
def apimrequests_patches():
127+
"""Provide common apimrequests patches for HTTP tests."""
128+
with MockApimRequestsPatches() as patches:
129+
yield patches

0 commit comments

Comments
 (0)