Skip to content
1 change: 1 addition & 0 deletions .github/python.instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ applyTo: '**/*.py'
- Add or update pytest unit tests when changing behavior.
- Prefer focused tests for the code being changed.
- Avoid tests that require live Azure access; mock Azure CLI interactions and `azure_resources` helpers.
- Abstract and consolidate common test overhead into the `test_helpers.py` file.

## Azure Helper Imports

Expand Down
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
},
"editor.formatOnSave": true
},

"[markdown]": {
"files.trimTrailingWhitespace": false
},
"terminal.integrated.defaultProfile.windows": "PowerShell",
"plantuml.render": "Local",
"plantuml.exportFormat": "svg",
Expand Down
399 changes: 87 additions & 312 deletions README.md

Large diffs are not rendered by default.

19 changes: 19 additions & 0 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,32 @@ This guide helps you resolve common issues when working with the Azure API Manag

## Table of Contents

- [Setup Issues](#setup-issues)
- [Deployment Errors](#deployment-errors)
- [Authentication Issues](#authentication-issues)
- [Notebook and Development Environment Issues](#notebook-and-development-environment-issues)
- [Azure CLI Issues](#azure-cli-issues)
- [Resource Management Issues](#resource-management-issues)
- [Getting Additional Help](#getting-additional-help)

## Setup Issues

If you encounter import errors (e.g., `ModuleNotFoundError: No module named 'requests'` or cannot import shared modules), try these steps:

1. **Fix Python path configuration**:
```bash
python setup/local_setup.py --generate-env
```

2. **Verify setup**:
```bash
python setup/verify_local_setup.py
```

3. **Restart VS Code** after running the above commands.

4. **Check Python interpreter**: Use `Ctrl+Shift+P` → "Python: Select Interpreter" and choose your `.venv` interpreter.

## Deployment Errors

### "The content for this response was already consumed"
Expand Down
2 changes: 1 addition & 1 deletion shared/python/infrastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _create_keyvault(self, key_vault_name: str) -> bool:
print_error('Failed to assign Key Vault Certificates Officer role to current user.\nThis is an RBAC permission issue - verify your account has sufficient permissions.')
return False

print_ok(' Assigned Key Vault Certificates Officer role to current user')
print_ok('Assigned Key Vault Certificates Officer role to current user')

# Brief wait for role assignment propagation
print_plain('⏳ Waiting for role assignment propagation (15 seconds)...')
Expand Down
1 change: 0 additions & 1 deletion shared/python/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ def __init__(self, rg_location: str, deployment: INFRASTRUCTURE, index: int, api
print_val('Infrastructure', self.deployment.value)
print_val('Index', self.index)
print_val('APIM SKU', self.apim_sku.value)
print_plain('')

# ------------------------------
# PUBLIC METHODS
Expand Down
22 changes: 11 additions & 11 deletions tests/Test-Matrix.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

**Date / time**: __________________

| Sample / Infrastructure | SIMPLE APIM | APIM ACA | AFD APIM PE | App Gateway APIM ACA |
|:----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|
| **INFRASTRUCTURE** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **authX** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **authX-pro** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **azure-maps** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **general** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **load-balancing** | **N/A** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **oauth-3rd-party** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **secure-blob-access** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **INFRASTRUCTURE clean-up** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| Sample / Infrastructure | SIMPLE APIM | APIM ACA | AFD APIM PE | App Gateway APIM ACA | App Gateway APIM PE |
|:----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|-----------------------------|
| **INFRASTRUCTURE** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **authX** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **authX-pro** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **azure-maps** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **general** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **load-balancing** | **N/A** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **oauth-3rd-party** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **secure-blob-access** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
| **INFRASTRUCTURE clean-up** | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container | ▢ Local<br>▢ Dev Container |
93 changes: 93 additions & 0 deletions tests/python/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
# Add the shared/python directory to the Python path for all tests
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../../shared/python')))

# Add the tests/python directory to import test_helpers
sys.path.insert(0, os.path.abspath(os.path.dirname(__file__)))

# APIM Samples imports
# pylint: disable=wrong-import-position
from test_helpers import (
create_mock_http_response,
create_mock_output,
create_sample_apis,
create_sample_policy_fragments,
get_sample_infrastructure_params,
MockApimRequestsPatches,
MockInfrastructuresPatches
)


# ------------------------------
# SHARED FIXTURES
Expand All @@ -34,3 +49,81 @@ def sample_test_data() -> dict[str, Any]:
'test_resource_group': 'rg-test-apim-01',
'test_location': 'eastus2'
}


# ------------------------------
# MOCK FIXTURES
# ------------------------------

@pytest.fixture(autouse=True)
def infrastructures_patches():
"""Automatically patch infrastructures dependencies for tests."""
with MockInfrastructuresPatches() as patches:
yield patches


@pytest.fixture
def mock_utils(infrastructures_patches):
"""Return the patched utils module for infrastructures tests."""
return infrastructures_patches.utils


@pytest.fixture
def mock_az(infrastructures_patches):
"""Return the patched azure_resources module for infrastructures tests."""
return infrastructures_patches.az


@pytest.fixture
def mock_az_success():
"""Pre-configured successful Azure CLI output."""
return create_mock_output(success=True, json_data={'result': 'success'})


@pytest.fixture
def mock_az_failure():
"""Pre-configured failed Azure CLI output."""
return create_mock_output(success=False, text='Error message')


@pytest.fixture
def sample_policy_fragments():
"""Provide sample policy fragments for testing."""
return create_sample_policy_fragments(count=2)


@pytest.fixture
def sample_apis():
"""Provide sample APIs for testing."""
return create_sample_apis(count=2)


@pytest.fixture
def sample_infrastructure_params() -> dict[str, Any]:
"""Provide common infrastructure parameters."""
return get_sample_infrastructure_params()


@pytest.fixture
def mock_http_response_200():
"""Pre-configured successful HTTP response."""
return create_mock_http_response(
status_code=200,
json_data={'result': 'ok'}
)


@pytest.fixture
def mock_http_response_error():
"""Pre-configured error HTTP response."""
return create_mock_http_response(
status_code=500,
text='Internal Server Error'
)


@pytest.fixture
def apimrequests_patches():
"""Provide common apimrequests patches for HTTP tests."""
with MockApimRequestsPatches() as patches:
yield patches
Loading
Loading