Skip to content

Commit 7a9ba4c

Browse files
Add tests
1 parent a73a4d1 commit 7a9ba4c

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

tests/python/test_infrastructures.py

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,6 +2495,129 @@ def test_disable_apim_public_access_returns_false_when_param_missing(mock_utils,
24952495

24962496
assert result is False
24972497
mock_az.run.assert_not_called()
2498+
def test_infrastructure_constructor_with_all_network_modes(mock_utils):
2499+
"""Test Infrastructure creation with all network mode options."""
2500+
# Test PUBLIC mode
2501+
infra_public = infrastructures.Infrastructure(
2502+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2503+
index=1,
2504+
rg_location='eastus',
2505+
networkMode=APIMNetworkMode.PUBLIC
2506+
)
2507+
assert infra_public.networkMode == APIMNetworkMode.PUBLIC
2508+
2509+
# Test EXTERNAL_VNET mode
2510+
infra_external = infrastructures.Infrastructure(
2511+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2512+
index=1,
2513+
rg_location='eastus',
2514+
networkMode=APIMNetworkMode.EXTERNAL_VNET
2515+
)
2516+
assert infra_external.networkMode == APIMNetworkMode.EXTERNAL_VNET
2517+
2518+
# Test INTERNAL_VNET mode
2519+
infra_internal = infrastructures.Infrastructure(
2520+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2521+
index=1,
2522+
rg_location='eastus',
2523+
networkMode=APIMNetworkMode.INTERNAL_VNET
2524+
)
2525+
assert infra_internal.networkMode == APIMNetworkMode.INTERNAL_VNET
2526+
2527+
2528+
@pytest.mark.unit
2529+
def test_infrastructure_constructor_with_all_sku_types(mock_utils):
2530+
"""Test Infrastructure creation with all APIM SKU types."""
2531+
sku_types = [
2532+
APIM_SKU.BASICV2,
2533+
APIM_SKU.STANDARDV2,
2534+
APIM_SKU.DEVELOPER,
2535+
APIM_SKU.BASIC,
2536+
APIM_SKU.STANDARD,
2537+
APIM_SKU.PREMIUM
2538+
]
2539+
2540+
for sku in sku_types:
2541+
infra = infrastructures.Infrastructure(
2542+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2543+
index=1,
2544+
rg_location='eastus',
2545+
apim_sku=sku
2546+
)
2547+
assert infra.apim_sku == sku
2548+
2549+
2550+
@pytest.mark.unit
2551+
def test_infrastructure_constructor_with_mixed_custom_components(mock_utils):
2552+
"""Test Infrastructure with combinations of custom APIs and policy fragments."""
2553+
# Only custom APIs, no PFs
2554+
api_only = infrastructures.Infrastructure(
2555+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2556+
index=1,
2557+
rg_location='eastus',
2558+
infra_apis=[API('api1', 'API 1', '/api1', 'API 1')],
2559+
infra_pfs=None
2560+
)
2561+
api_only._define_policy_fragments()
2562+
api_only._define_apis()
2563+
assert len(api_only.apis) == 2 # hello-world + api1
2564+
assert len(api_only.pfs) == 6 # only base fragments
2565+
2566+
# Only custom PFs, no APIs
2567+
pf_only = infrastructures.Infrastructure(
2568+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2569+
index=1,
2570+
rg_location='eastus',
2571+
infra_apis=None,
2572+
infra_pfs=[PolicyFragment('pf1', '<policy/>', 'PF 1')]
2573+
)
2574+
pf_only._define_policy_fragments()
2575+
pf_only._define_apis()
2576+
assert len(pf_only.apis) == 1 # only hello-world
2577+
assert len(pf_only.pfs) == 7 # 6 base + pf1
2578+
2579+
2580+
@pytest.mark.unit
2581+
def test_infrastructure_constructor_extreme_index_values(mock_utils):
2582+
"""Test Infrastructure creation with edge-case index values."""
2583+
# Index 0
2584+
infra_zero = infrastructures.Infrastructure(
2585+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2586+
index=0,
2587+
rg_location='eastus'
2588+
)
2589+
assert isinstance(infra_zero.index, int) and infra_zero.index >= 0 # Zero is valid
2590+
2591+
# Large index
2592+
infra_large = infrastructures.Infrastructure(
2593+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2594+
index=9999,
2595+
rg_location='eastus'
2596+
)
2597+
assert infra_large.index == 9999
2598+
2599+
# Negative index (although not typical, should still work)
2600+
infra_negative = infrastructures.Infrastructure(
2601+
infra=INFRASTRUCTURE.SIMPLE_APIM,
2602+
index=-1,
2603+
rg_location='eastus'
2604+
)
2605+
assert infra_negative.index == -1
2606+
2607+
2608+
@pytest.mark.unit
2609+
def test_infrastructure_constructor_with_all_infrastructure_types(mock_utils):
2610+
"""Test that base Infrastructure can be instantiated with all infrastructure types."""
2611+
for infra_type in INFRASTRUCTURE:
2612+
infra = infrastructures.Infrastructure(
2613+
infra=infra_type,
2614+
index=1,
2615+
rg_location='eastus'
2616+
)
2617+
assert infra.infra == infra_type
2618+
2619+
2620+
@pytest.mark.unit
24982621

24992622

25002623
@pytest.mark.unit

0 commit comments

Comments
 (0)