1010# Add the shared/python directory to the Python path for all tests
1111sys .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