Skip to content

Commit c5ed2f8

Browse files
Fix failing tests
1 parent 96323af commit c5ed2f8

File tree

2 files changed

+9
-55
lines changed

2 files changed

+9
-55
lines changed

tests/python/test_helpers.py

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,10 @@
77
import builtins
88
from collections.abc import Callable
99
from unittest.mock import Mock, MagicMock, mock_open, patch
10+
import json as json_module
1011

1112
# APIM Samples imports
12-
from apimtypes import (
13-
APIM_SKU,
14-
APIMNetworkMode,
15-
API,
16-
APIOperation,
17-
PolicyFragment,
18-
Output,
19-
HTTP_VERB
20-
)
13+
from apimtypes import APIM_SKU, APIMNetworkMode, API, APIOperation, PolicyFragment, Output, HTTP_VERB
2114

2215

2316
# ------------------------------
@@ -417,7 +410,6 @@ def create_mock_http_response(
417410
headers = {'Content-Type': 'application/json'}
418411

419412
if json_data is not None and text is None:
420-
import json as json_module
421413
text = json_module.dumps(json_data, indent=4)
422414
elif text is None:
423415
text = ''

tests/python/test_infrastructures.py

Lines changed: 7 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -24,57 +24,19 @@
2424

2525

2626
# ------------------------------
27-
# FIXTURES
27+
# FIXTURE ALIASES
2828
# ------------------------------
2929

3030
@pytest.fixture
31-
def mock_utils():
32-
"""Mock the utils module to avoid external dependencies."""
33-
with patch('infrastructures.utils') as mock_utils:
34-
mock_utils.build_infrastructure_tags.return_value = {'environment': 'test', 'project': 'apim-samples'}
35-
mock_utils.read_policy_xml.return_value = '<policies><inbound><base /></inbound></policies>'
36-
mock_utils.determine_shared_policy_path.return_value = '/mock/path/policy.xml'
37-
mock_utils.verify_infrastructure.return_value = True
38-
39-
yield mock_utils
40-
41-
42-
@pytest.fixture(autouse = True)
43-
def mock_az():
44-
"""Mock the azure_resources module used by infrastructures."""
45-
46-
with patch('infrastructures.az') as mock_az:
47-
mock_az.get_infra_rg_name.return_value = 'rg-test-infrastructure-01'
48-
mock_az.create_resource_group.return_value = None
49-
mock_az.does_resource_group_exist.return_value = True
50-
mock_az.get_account_info.return_value = ('test_user', 'test_user_id', 'test_tenant', 'test_subscription')
51-
mock_az.get_unique_suffix_for_resource_group.return_value = 'abc123def456'
52-
53-
# Mock the run command with proper return object
54-
mock_output = Mock()
55-
mock_output.success = True
56-
mock_output.json_data = {'outputs': 'test'}
57-
mock_output.get.return_value = 'https://test-apim.azure-api.net'
58-
mock_output.getJson.return_value = ['api1', 'api2']
59-
mock_az.run.return_value = mock_output
60-
61-
yield mock_az
31+
def mock_policy_fragments(sample_policy_fragments):
32+
"""Alias to keep older test signatures stable."""
33+
return sample_policy_fragments
6234

63-
@pytest.fixture
64-
def mock_policy_fragments():
65-
"""Provide mock policy fragments for testing."""
66-
return [
67-
PolicyFragment('Test-Fragment-1', '<policy>test1</policy>', 'Test fragment 1'),
68-
PolicyFragment('Test-Fragment-2', '<policy>test2</policy>', 'Test fragment 2')
69-
]
7035

7136
@pytest.fixture
72-
def mock_apis():
73-
"""Provide mock APIs for testing."""
74-
return [
75-
API('test-api-1', 'Test API 1', '/test1', 'Test API 1 description', '<policy>api1</policy>'),
76-
API('test-api-2', 'Test API 2', '/test2', 'Test API 2 description', '<policy>api2</policy>')
77-
]
37+
def mock_apis(sample_apis):
38+
"""Alias to keep older test signatures stable."""
39+
return sample_apis
7840

7941

8042
# ------------------------------

0 commit comments

Comments
 (0)