Skip to content

Commit 7d20d46

Browse files
committed
Add tests for template specs with auxiliary subscription
Introduces new test cases to validate update, show, delete and export operations for template specs using an auxiliary subscription.
1 parent 077ba98 commit 7d20d46

File tree

1 file changed

+108
-0
lines changed

1 file changed

+108
-0
lines changed

src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,29 @@ def test_update_template_specs(self, resource_group, resource_group_location):
10161016
# clean up
10171017
self.cmd('ts delete --template-spec {template_spec_id} --yes')
10181018

1019+
@live_only()
1020+
@ResourceGroupPreparer(name_prefix="cli_test_ts_aux_update_", location="eastus2", subscription=AUX_SUBSCRIPTION)
1021+
def test_update_template_spec_with_aux_subscription(self, resource_group):
1022+
curr_dir = os.path.dirname(os.path.realpath(__file__))
1023+
template_spec_name = self.create_random_name('cli-test-ts-aux-update', 60)
1024+
self.kwargs.update({
1025+
"aux_rg": resource_group,
1026+
"aux_subscription": AUX_SUBSCRIPTION,
1027+
"template_spec_name": template_spec_name,
1028+
'tf': os.path.join(curr_dir, 'simple_deploy.json').replace('\\', '\\\\'),
1029+
'description': '"Updated description"',
1030+
})
1031+
1032+
result = self.cmd('ts create -g {aux_rg} -n {template_spec_name} -v 1.0 -l eastus2 -f "{tf}" --subscription {aux_subscription}').get_output_in_json()
1033+
self.kwargs['template_spec_version_id'] = result['id']
1034+
self.kwargs['template_spec_id'] = result['id'].replace('/versions/1.0', '')
1035+
self.assertIn(AUX_SUBSCRIPTION, result['id'])
1036+
1037+
ts_result = self.cmd('ts update --template-spec {template_spec_id} --description {description} --yes').get_output_in_json()
1038+
self.assertIn(AUX_SUBSCRIPTION, ts_result['id'])
1039+
1040+
self.cmd('ts delete --template-spec {template_spec_id} --yes --subscription {aux_subscription}')
1041+
10191042
@ResourceGroupPreparer(name_prefix='cli_test_template_specs', location='westus')
10201043
def test_show_template_spec(self, resource_group, resource_group_location):
10211044
curr_dir = os.path.dirname(os.path.realpath(__file__))
@@ -1047,6 +1070,46 @@ def test_show_template_spec(self, resource_group, resource_group_location):
10471070
# clean up
10481071
self.cmd('ts delete --template-spec {template_spec_id} --yes')
10491072

1073+
@live_only()
1074+
@ResourceGroupPreparer(name_prefix="cli_test_ts_aux_show_", location="eastus2", subscription=AUX_SUBSCRIPTION)
1075+
def test_template_spec_show_with_aux_subscription(self, resource_group, resource_group_location):
1076+
curr_dir = os.path.dirname(os.path.realpath(__file__))
1077+
template_spec_name = self.create_random_name('cli-test-ts-aux-show', 60)
1078+
self.kwargs.update({
1079+
"aux_rg": resource_group,
1080+
"aux_subscription": AUX_SUBSCRIPTION,
1081+
"template_spec_name": template_spec_name,
1082+
'tf': os.path.join(curr_dir, 'simple_deploy.json').replace('\\', '\\\\'),
1083+
'resource_group_location': resource_group_location,
1084+
})
1085+
1086+
result = self.cmd('ts create -g {aux_rg} -n {template_spec_name} -v 1.0 -l {resource_group_location} -f "{tf}" --subscription {aux_subscription}',
1087+
checks=[
1088+
self.check('name', '1.0'),
1089+
self.check('type', 'Microsoft.Resources/templateSpecs/versions')
1090+
]).get_output_in_json()
1091+
self.kwargs['template_spec_version_id'] = result['id']
1092+
self.kwargs['template_spec_id'] = result['id'].replace('/versions/1.0', '')
1093+
self.assertIn(AUX_SUBSCRIPTION, result['id'])
1094+
1095+
ts_result = self.cmd('ts show --template-spec {template_spec_id}',
1096+
checks=[
1097+
self.check('name', '{template_spec_name}'),
1098+
self.check('type', 'Microsoft.Resources/templateSpecs')
1099+
]).get_output_in_json()
1100+
self.assertIn(AUX_SUBSCRIPTION, ts_result['id'])
1101+
self.assertEqual(ts_result['name'], template_spec_name)
1102+
1103+
ts_version_result = self.cmd('ts show --template-spec {template_spec_version_id}',
1104+
checks=[
1105+
self.check('name', '1.0'),
1106+
self.check('type', 'Microsoft.Resources/templateSpecs/versions')
1107+
]).get_output_in_json()
1108+
self.assertIn(AUX_SUBSCRIPTION, ts_version_result['id'])
1109+
self.assertEqual(ts_version_result['name'], '1.0')
1110+
1111+
self.cmd('ts delete --template-spec {template_spec_id} --yes --subscription {aux_subscription}')
1112+
10501113
@ResourceGroupPreparer(name_prefix='cli_test_template_specs', location='westus')
10511114
def test_delete_template_spec(self, resource_group, resource_group_location):
10521115
curr_dir = os.path.dirname(os.path.realpath(__file__))
@@ -1076,6 +1139,25 @@ def test_delete_template_spec(self, resource_group, resource_group_location):
10761139
self.cmd('ts list -g {rg}',
10771140
checks=self.check("length([?id=='{template_spec_id}'])", 0))
10781141

1142+
@live_only()
1143+
@ResourceGroupPreparer(name_prefix="cli_test_ts_aux_delete_", location="eastus2", subscription=AUX_SUBSCRIPTION)
1144+
def test_delete_template_spec_with_aux_subscription(self, resource_group):
1145+
curr_dir = os.path.dirname(os.path.realpath(__file__))
1146+
template_spec_name = self.create_random_name('cli-test-ts-aux-delete', 60)
1147+
self.kwargs.update({
1148+
"aux_rg": resource_group,
1149+
"aux_subscription": AUX_SUBSCRIPTION,
1150+
"template_spec_name": template_spec_name,
1151+
'tf': os.path.join(curr_dir, 'simple_deploy.json').replace('\\', '\\\\'),
1152+
})
1153+
1154+
result = self.cmd('ts create -g {aux_rg} -n {template_spec_name} -v 1.0 -l eastus2 -f "{tf}" --subscription {aux_subscription}').get_output_in_json()
1155+
self.kwargs['template_spec_version_id'] = result['id']
1156+
self.kwargs['template_spec_id'] = result['id'].replace('/versions/1.0', '')
1157+
self.assertIn(AUX_SUBSCRIPTION, result['id'])
1158+
1159+
self.cmd('ts delete --template-spec {template_spec_id} --yes')
1160+
10791161
@ResourceGroupPreparer(name_prefix='cli_test_template_specs', location='westus')
10801162
def test_template_spec_create_and_update_with_tags(self, resource_group, resource_group_location):
10811163
curr_dir = os.path.dirname(os.path.realpath(__file__))
@@ -1197,6 +1279,32 @@ def test_template_spec_export_error_handling(self, resource_group, resource_grou
11971279
self.cmd('ts export -g {rg} --name {template_spec_name} --output-folder {output_folder}')
11981280
self.assertTrue('Please specify the template spec version for export' in str(err.exception))
11991281

1282+
@live_only()
1283+
@ResourceGroupPreparer(name_prefix="cli_test_ts_aux_export_", location="eastus2", subscription=AUX_SUBSCRIPTION)
1284+
def test_template_spec_export_with_aux_subscription(self, resource_group):
1285+
curr_dir = os.path.dirname(os.path.realpath(__file__))
1286+
dir_name = self.create_random_name('TemplateSpecExportAux', 30)
1287+
template_spec_name = self.create_random_name('cli-test-ts-aux-export', 60)
1288+
self.kwargs.update({
1289+
"aux_rg": resource_group,
1290+
"aux_subscription": AUX_SUBSCRIPTION,
1291+
"template_spec_name": template_spec_name,
1292+
'tf': os.path.join(curr_dir, 'simple_deploy.json').replace('\\', '\\\\'),
1293+
'output_folder': os.path.join(curr_dir, dir_name).replace('\\', '\\\\'),
1294+
})
1295+
1296+
result = self.cmd('ts create -g {aux_rg} -n {template_spec_name} -v 1.0 -l eastus2 -f "{tf}" --subscription {aux_subscription}').get_output_in_json()
1297+
self.kwargs['template_spec_version_id'] = result['id']
1298+
self.kwargs['template_spec_id'] = result['id'].replace('/versions/1.0', '')
1299+
self.assertIn(AUX_SUBSCRIPTION, result['id'])
1300+
1301+
os.makedirs(self.kwargs['output_folder'])
1302+
output_path = self.cmd('ts export --template-spec {template_spec_version_id} --output-folder {output_folder}').get_output_in_json()
1303+
template_file = os.path.join(output_path, (self.kwargs['template_spec_name'] + '.json'))
1304+
self.assertTrue(os.path.isfile(template_file))
1305+
1306+
self.cmd('ts delete --template-spec {template_spec_id} --yes --subscription {aux_subscription}')
1307+
12001308

12011309
class DeploymentTestsWithQueryString(LiveScenarioTest):
12021310
@ResourceGroupPreparer(name_prefix='cli_test_query_str_rg', location='eastus')

0 commit comments

Comments
 (0)