|
| 1 | +# ------------------------------------------------------------------------- |
| 2 | +# Copyright (c) Microsoft Corporation. All rights reserved. |
| 3 | +# Licensed under the MIT License. See License.txt in the project root for |
| 4 | +# license information. |
| 5 | +# -------------------------------------------------------------------------- |
| 6 | +import pytest |
| 7 | +from azure.resourcemanager.methodsubscriptionid.aio import MethodSubscriptionIdClient |
| 8 | +from azure.resourcemanager.methodsubscriptionid import models |
| 9 | + |
| 10 | +SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000" |
| 11 | +RESOURCE_GROUP_NAME = "test-rg" |
| 12 | + |
| 13 | + |
| 14 | +@pytest.fixture |
| 15 | +async def client(credential, authentication_policy): |
| 16 | + async with MethodSubscriptionIdClient( |
| 17 | + credential, |
| 18 | + SUBSCRIPTION_ID, |
| 19 | + "http://localhost:3000", |
| 20 | + authentication_policy=authentication_policy, |
| 21 | + ) as client: |
| 22 | + yield client |
| 23 | + |
| 24 | + |
| 25 | +@pytest.mark.asyncio |
| 26 | +async def test_operations_list(client): |
| 27 | + """Test Operations.list() endpoint.""" |
| 28 | + operations = client.operations.list() |
| 29 | + operations_list = [op async for op in operations] |
| 30 | + assert len(operations_list) > 0 |
| 31 | + |
| 32 | + operation = operations_list[0] |
| 33 | + assert operation.name == "Azure.ResourceManager.MethodSubscriptionId/services/read" |
| 34 | + assert operation.is_data_action is False |
| 35 | + assert operation.display.provider == "Azure.ResourceManager.MethodSubscriptionId" |
| 36 | + assert operation.display.resource == "services" |
| 37 | + assert operation.display.operation == "Lists services" |
| 38 | + assert operation.display.description == "Lists registered services" |
| 39 | + |
| 40 | + |
| 41 | +@pytest.mark.asyncio |
| 42 | +async def test_two_subscription_resources_method_level_subscription_resource1_operations_get(client): |
| 43 | + """Test get operation for SubscriptionResource1 with method-level subscription ID.""" |
| 44 | + result = await client.two_subscription_resources_method_level.subscription_resource1_operations.get( |
| 45 | + subscription_id=SUBSCRIPTION_ID, |
| 46 | + subscription_resource1_name="sub-resource-1", |
| 47 | + ) |
| 48 | + |
| 49 | + assert ( |
| 50 | + result.id |
| 51 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" |
| 52 | + ) |
| 53 | + assert result.name == "sub-resource-1" |
| 54 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" |
| 55 | + assert result.properties.description == "Valid subscription resource 1" |
| 56 | + assert result.properties.provisioning_state == "Succeeded" |
| 57 | + assert result.system_data.created_by == "AzureSDK" |
| 58 | + |
| 59 | + |
| 60 | +@pytest.mark.asyncio |
| 61 | +async def test_two_subscription_resources_method_level_subscription_resource1_operations_put(client): |
| 62 | + """Test put operation for SubscriptionResource1 with method-level subscription ID.""" |
| 63 | + resource = models.SubscriptionResource1( |
| 64 | + properties=models.SubscriptionResource1Properties(description="Valid subscription resource 1") |
| 65 | + ) |
| 66 | + |
| 67 | + result = await client.two_subscription_resources_method_level.subscription_resource1_operations.put( |
| 68 | + subscription_id=SUBSCRIPTION_ID, |
| 69 | + subscription_resource1_name="sub-resource-1", |
| 70 | + resource=resource, |
| 71 | + ) |
| 72 | + |
| 73 | + assert ( |
| 74 | + result.id |
| 75 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s/sub-resource-1" |
| 76 | + ) |
| 77 | + assert result.name == "sub-resource-1" |
| 78 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource1s" |
| 79 | + assert result.properties.description == "Valid subscription resource 1" |
| 80 | + assert result.properties.provisioning_state == "Succeeded" |
| 81 | + assert result.system_data.created_by == "AzureSDK" |
| 82 | + |
| 83 | + |
| 84 | +@pytest.mark.asyncio |
| 85 | +async def test_two_subscription_resources_method_level_subscription_resource1_operations_delete(client): |
| 86 | + """Test delete operation for SubscriptionResource1 with method-level subscription ID.""" |
| 87 | + await client.two_subscription_resources_method_level.subscription_resource1_operations.delete( |
| 88 | + subscription_id=SUBSCRIPTION_ID, |
| 89 | + subscription_resource1_name="sub-resource-1", |
| 90 | + ) |
| 91 | + |
| 92 | + |
| 93 | +@pytest.mark.asyncio |
| 94 | +async def test_two_subscription_resources_method_level_subscription_resource2_operations_get(client): |
| 95 | + """Test get operation for SubscriptionResource2 with method-level subscription ID.""" |
| 96 | + result = await client.two_subscription_resources_method_level.subscription_resource2_operations.get( |
| 97 | + subscription_id=SUBSCRIPTION_ID, |
| 98 | + subscription_resource2_name="sub-resource-2", |
| 99 | + ) |
| 100 | + |
| 101 | + assert ( |
| 102 | + result.id |
| 103 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" |
| 104 | + ) |
| 105 | + assert result.name == "sub-resource-2" |
| 106 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" |
| 107 | + assert result.properties.config_value == "test-config" |
| 108 | + assert result.properties.provisioning_state == "Succeeded" |
| 109 | + assert result.system_data.created_by == "AzureSDK" |
| 110 | + |
| 111 | + |
| 112 | +@pytest.mark.asyncio |
| 113 | +async def test_two_subscription_resources_method_level_subscription_resource2_operations_put(client): |
| 114 | + """Test put operation for SubscriptionResource2 with method-level subscription ID.""" |
| 115 | + resource = models.SubscriptionResource2( |
| 116 | + properties=models.SubscriptionResource2Properties(config_value="test-config") |
| 117 | + ) |
| 118 | + |
| 119 | + result = await client.two_subscription_resources_method_level.subscription_resource2_operations.put( |
| 120 | + subscription_id=SUBSCRIPTION_ID, |
| 121 | + subscription_resource2_name="sub-resource-2", |
| 122 | + resource=resource, |
| 123 | + ) |
| 124 | + |
| 125 | + assert ( |
| 126 | + result.id |
| 127 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s/sub-resource-2" |
| 128 | + ) |
| 129 | + assert result.name == "sub-resource-2" |
| 130 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResource2s" |
| 131 | + assert result.properties.config_value == "test-config" |
| 132 | + assert result.properties.provisioning_state == "Succeeded" |
| 133 | + assert result.system_data.created_by == "AzureSDK" |
| 134 | + |
| 135 | + |
| 136 | +@pytest.mark.asyncio |
| 137 | +async def test_two_subscription_resources_method_level_subscription_resource2_operations_delete(client): |
| 138 | + """Test delete operation for SubscriptionResource2 with method-level subscription ID.""" |
| 139 | + await client.two_subscription_resources_method_level.subscription_resource2_operations.delete( |
| 140 | + subscription_id=SUBSCRIPTION_ID, |
| 141 | + subscription_resource2_name="sub-resource-2", |
| 142 | + ) |
| 143 | + |
| 144 | + |
| 145 | +@pytest.mark.asyncio |
| 146 | +async def test_mixed_subscription_placement_subscription_resource_operations_get(client): |
| 147 | + """Test get operation for SubscriptionResource in mixed placement scenario.""" |
| 148 | + result = await client.mixed_subscription_placement.subscription_resource_operations.get( |
| 149 | + subscription_id=SUBSCRIPTION_ID, |
| 150 | + subscription_resource_name="sub-resource", |
| 151 | + ) |
| 152 | + |
| 153 | + assert ( |
| 154 | + result.id |
| 155 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" |
| 156 | + ) |
| 157 | + assert result.name == "sub-resource" |
| 158 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" |
| 159 | + assert result.properties.subscription_setting == "test-sub-setting" |
| 160 | + assert result.properties.provisioning_state == "Succeeded" |
| 161 | + assert result.system_data.created_by == "AzureSDK" |
| 162 | + |
| 163 | + |
| 164 | +@pytest.mark.asyncio |
| 165 | +async def test_mixed_subscription_placement_subscription_resource_operations_put(client): |
| 166 | + """Test put operation for SubscriptionResource in mixed placement scenario.""" |
| 167 | + resource = models.SubscriptionResource( |
| 168 | + properties=models.SubscriptionResourceProperties(subscription_setting="test-sub-setting") |
| 169 | + ) |
| 170 | + |
| 171 | + result = await client.mixed_subscription_placement.subscription_resource_operations.put( |
| 172 | + subscription_id=SUBSCRIPTION_ID, |
| 173 | + subscription_resource_name="sub-resource", |
| 174 | + resource=resource, |
| 175 | + ) |
| 176 | + |
| 177 | + assert ( |
| 178 | + result.id |
| 179 | + == f"/subscriptions/{SUBSCRIPTION_ID}/providers/Azure.ResourceManager.MethodSubscriptionId/subscriptionResources/sub-resource" |
| 180 | + ) |
| 181 | + assert result.name == "sub-resource" |
| 182 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/subscriptionResources" |
| 183 | + assert result.properties.subscription_setting == "test-sub-setting" |
| 184 | + assert result.properties.provisioning_state == "Succeeded" |
| 185 | + assert result.system_data.created_by == "AzureSDK" |
| 186 | + |
| 187 | + |
| 188 | +@pytest.mark.asyncio |
| 189 | +async def test_mixed_subscription_placement_subscription_resource_operations_delete(client): |
| 190 | + """Test delete operation for SubscriptionResource in mixed placement scenario.""" |
| 191 | + await client.mixed_subscription_placement.subscription_resource_operations.delete( |
| 192 | + subscription_id=SUBSCRIPTION_ID, |
| 193 | + subscription_resource_name="sub-resource", |
| 194 | + ) |
| 195 | + |
| 196 | + |
| 197 | +@pytest.mark.asyncio |
| 198 | +async def test_mixed_subscription_placement_resource_group_resource_operations_get(client): |
| 199 | + """Test get operation for ResourceGroupResource with client-level subscription ID.""" |
| 200 | + result = await client.mixed_subscription_placement.resource_group_resource_operations.get( |
| 201 | + resource_group_name=RESOURCE_GROUP_NAME, |
| 202 | + resource_group_resource_name="rg-resource", |
| 203 | + ) |
| 204 | + |
| 205 | + assert ( |
| 206 | + result.id |
| 207 | + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" |
| 208 | + ) |
| 209 | + assert result.name == "rg-resource" |
| 210 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" |
| 211 | + assert result.location == "eastus" |
| 212 | + assert result.properties.resource_group_setting == "test-setting" |
| 213 | + assert result.properties.provisioning_state == "Succeeded" |
| 214 | + assert result.system_data.created_by == "AzureSDK" |
| 215 | + |
| 216 | + |
| 217 | +@pytest.mark.asyncio |
| 218 | +async def test_mixed_subscription_placement_resource_group_resource_operations_put(client): |
| 219 | + """Test put operation for ResourceGroupResource with client-level subscription ID.""" |
| 220 | + resource = models.ResourceGroupResource( |
| 221 | + location="eastus", properties=models.ResourceGroupResourceProperties(resource_group_setting="test-setting") |
| 222 | + ) |
| 223 | + |
| 224 | + result = await client.mixed_subscription_placement.resource_group_resource_operations.put( |
| 225 | + resource_group_name=RESOURCE_GROUP_NAME, |
| 226 | + resource_group_resource_name="rg-resource", |
| 227 | + resource=resource, |
| 228 | + ) |
| 229 | + |
| 230 | + assert ( |
| 231 | + result.id |
| 232 | + == f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{RESOURCE_GROUP_NAME}/providers/Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources/rg-resource" |
| 233 | + ) |
| 234 | + assert result.name == "rg-resource" |
| 235 | + assert result.type == "Azure.ResourceManager.MethodSubscriptionId/resourceGroupResources" |
| 236 | + assert result.location == "eastus" |
| 237 | + assert result.properties.resource_group_setting == "test-setting" |
| 238 | + assert result.properties.provisioning_state == "Succeeded" |
| 239 | + assert result.system_data.created_by == "AzureSDK" |
| 240 | + |
| 241 | + |
| 242 | +@pytest.mark.asyncio |
| 243 | +async def test_mixed_subscription_placement_resource_group_resource_operations_delete(client): |
| 244 | + """Test delete operation for ResourceGroupResource with client-level subscription ID.""" |
| 245 | + await client.mixed_subscription_placement.resource_group_resource_operations.delete( |
| 246 | + resource_group_name=RESOURCE_GROUP_NAME, |
| 247 | + resource_group_resource_name="rg-resource", |
| 248 | + ) |
0 commit comments