Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

{CI} Replace deprecated assertRaisesRegexp and assertEquals #8010

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def test_account(self):
self.check('subscriptionId', sub_id)]).get_output_in_json()
if sub['state'] != 'Warned':
time.sleep(180)
self.assertEquals(sub['state'], 'Warned')
self.assertEqual(sub['state'], 'Warned')

self.cmd('az account subscription enable --subscription-id {subscription_id}',
checks=[self.check('subscriptionId', '{subscription_id}')])
Expand All @@ -71,7 +71,7 @@ def test_account(self):
self.check('subscriptionId', sub_id)]).get_output_in_json()
if sub['state'] != 'Enabled':
time.sleep(180)
self.assertEquals(sub['state'], 'Enabled')
self.assertEqual(sub['state'], 'Enabled')

self.cmd('az account subscription rename --subscription-id {subscription_id} --name "{new_display_name}"',
checks=[self.check('subscriptionId', '{subscription_id}')])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def test_definition_import_large_value(self):
with open(self.kwargs['file_name'], 'w') as file:
file.write('a' * 4 * 1024 * 1024) # generate a 4MB file

with self.assertRaisesRegexp(CLIError, 'The size of "value" is greater than 3 MB. Please use --format "link" to import the specification from a URL for size greater than 3 mb.') as cm:
with self.assertRaisesRegex(CLIError, 'The size of "value" is greater than 3 MB. Please use --format "link" to import the specification from a URL for size greater than 3 mb.') as cm:
self.cmd('az apic api definition import-specification -g {rg} -n {s} --api-id {api} --version-id {v} --definition-id {d} --format "inline" --specification \'{specification}\' --value "@{file_name}"')
finally:
os.remove(self.kwargs['file_name'])
Expand Down Expand Up @@ -310,4 +310,4 @@ def test_examples_export_specification(self):
# Check the exported file exists
assert os.path.exists(self.kwargs['filename'])
finally:
os.remove(self.kwargs['filename'])
os.remove(self.kwargs['filename'])
18 changes: 9 additions & 9 deletions src/authV2/azext_authV2/tests/latest/test_authV2_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,42 +38,42 @@ def test_authV2_clientsecret_param_combinations(self, resource_group):
JMESPathCheck('platform', "{'enabled': True, 'runtimeVersion': '1.2.8'}")
])

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --client-secret and --client-secret-setting-name cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --client-secret and --client-secret-setting-name cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --client-secret test --client-secret-setting-name test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --client-secret-setting-name and --thumbprint cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --client-secret-setting-name and --thumbprint cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --client-secret-setting-name test --thumbprint test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --client-secret and --thumbprint cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --client-secret and --thumbprint cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --client-secret test --thumbprint test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --client-secret and --san cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --client-secret and --san cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --client-secret test --san test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --client-secret-setting-name and --san cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --client-secret-setting-name and --san cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --client-secret-setting-name test --san test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --thumbprint and --san cannot both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --thumbprint and --san cannot both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --thumbprint test --san test2'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --san and --certificate-issuer must both be '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --san and --certificate-issuer must both be '
'configured to non empty strings'):
self.cmd('webapp auth Microsoft update -g {} -n {} --san test'
.format(resource_group, webapp_name))

with self.assertRaisesRegexp(ArgumentUsageError, 'Usage Error: --issuer and --tenant-id cannot be configured '
with self.assertRaisesRegex(ArgumentUsageError, 'Usage Error: --issuer and --tenant-id cannot be configured '
'to non empty strings at the same time.'):
self.cmd('webapp auth Microsoft update -g {} -n {} --issuer test --tenant-id test2'
.format(resource_group, webapp_name))
Expand Down Expand Up @@ -153,4 +153,4 @@ def test_authV2_authclassic(self, resource_group):
JMESPathCheck('issuer', 'https://issuer_url'),
JMESPathCheck('facebookAppId', 'facebook_id')]).get_output_in_json()

self.assertIn('https://audience1', result['allowedAudiences'])
self.assertIn('https://audience1', result['allowedAudiences'])
Original file line number Diff line number Diff line change
Expand Up @@ -363,13 +363,13 @@ def test_automation_dsc_configuration(self, resource_group):
])

config_content = self.cmd('automation configuration show-content -g {rg} --automation-account-name {account} -n {config}')
self.assertEquals(self.kwargs['source_content_retrieved'], config_content.output)
self.assertEqual(self.kwargs['source_content_retrieved'], config_content.output)

self.cmd('automation configuration update -g {rg} --automation-account-name {account} -n {config} --location {location} '
'--source-type embeddedContent --source {source_content2}')

config_content = self.cmd('automation configuration show-content -g {rg} --automation-account-name {account} -n {config}')
self.assertEquals(self.kwargs['source_content2_retrieved'], config_content.output)
self.assertEqual(self.kwargs['source_content2_retrieved'], config_content.output)

self.cmd('automation configuration delete -g {rg} --automation-account-name {account} -n {config} -y')
self.cmd('automation configuration list -g {rg} --automation-account-name {account}', checks=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ def test_azure_firewall_virtual_hub(self, resource_group):
# self.cmd('network firewall create -g {rg} -n {af} --sku AZFW_Hub --count 1 --vhub {vhub}')
# self.cmd('network firewall update -g {rg} -n {af} --vhub ""')

# with self.assertRaisesRegexp(CLIError, "allow active ftp is not allowed for azure firewall on virtual hub."):
# with self.assertRaisesRegex(CLIError, "allow active ftp is not allowed for azure firewall on virtual hub."):
# self.cmd('network firewall create -g {rg} -n {af} --sku AZFW_Hub --count 1 --vhub {vhub} --allow-active-ftp')

self.cmd('network vwan create -n {vwan2} -g {rg} --type Standard')
Expand Down Expand Up @@ -1471,4 +1471,4 @@ def test_azure_policy_idps_profiles(self, resource_group, resource_group_locatio
])

# delete policy 2
self.cmd('network firewall policy delete -g {rg} --name {policy_name_2}')
self.cmd('network firewall policy delete -g {rg} --name {policy_name_2}')
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ def test_enable_disable_features(self, resource_group):
] == bool(1)

# scenario-2 : custom loc is enabled , check if disabling cluster connect results in an error
with self.assertRaisesRegexp(
with self.assertRaisesRegex(
CLIError,
"Disabling 'cluster-connect' feature is not allowed when \
'custom-locations' feature is enabled.",
Expand Down Expand Up @@ -678,7 +678,7 @@ def test_upgrade(self, resource_group):
"-ojson",
]

with self.assertRaisesRegexp(
with self.assertRaisesRegex(
CLIError,
"az connectedk8s upgrade to manually upgrade agents and extensions is \
only supported when auto-upgrade is set to false",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def test_containerapp_patch_list_and_apply_with_resource_group_e2e(self, resourc
# Execute and verify patch list command
patchable_images = self.cmd(f'containerapp patch list -g {resource_group}').get_output_in_json()
self.assertTrue(len(patchable_images) == 1)
self.assertEquals(patchable_images[0]["oldRunImage"], builder_runtime_image)
self.assertEqual(patchable_images[0]["oldRunImage"], builder_runtime_image)

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply -g {resource_group}')
Expand Down Expand Up @@ -91,7 +91,7 @@ def test_containerapp_patch_list_and_apply_with_environment_e2e(self, resource_g
# Execute and verify patch list command
patchable_images = self.cmd(f'containerapp patch list -g {resource_group} --environment {env_name}').get_output_in_json()
self.assertTrue(len(patchable_images) == 1)
self.assertEquals(patchable_images[0]["oldRunImage"], builder_runtime_image)
self.assertEqual(patchable_images[0]["oldRunImage"], builder_runtime_image)

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply -g {resource_group} --environment {env_name}')
Expand Down Expand Up @@ -119,13 +119,13 @@ def test_containerapp_patch_list_and_apply_with_show_all_e2e(self, resource_grou
# Execute and verify patch list command
patch_cmd = f'containerapp patch list -g {resource_group} --environment {env_name} --show-all'
output = self.cmd(patch_cmd).get_output_in_json()
self.assertEquals(output[0]["targetImageName"], "mcr.microsoft.com/k8se/quickstart:latest")
self.assertEqual(output[0]["targetImageName"], "mcr.microsoft.com/k8se/quickstart:latest")

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply -g {resource_group} --environment {env_name} --show-all')
app = self.cmd(f"containerapp show -g {resource_group} -n {app_name}").get_output_in_json()
image = app["properties"]["template"]["containers"][0]["image"]
self.assertEquals(image, "mcr.microsoft.com/k8se/quickstart:latest")
self.assertEqual(image, "mcr.microsoft.com/k8se/quickstart:latest")


@live_only()
Expand Down Expand Up @@ -158,7 +158,7 @@ def test_containerapp_patch_list_and_apply_without_arguments_e2e(self, resource_
self.cmd(f'configure --defaults group={resource_group}')
patchable_images = self.cmd(f'containerapp patch list').get_output_in_json()
self.assertTrue(len(patchable_images) == 1)
self.assertEquals(patchable_images[0]["oldRunImage"], builder_runtime_image)
self.assertEqual(patchable_images[0]["oldRunImage"], builder_runtime_image)

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply')
Expand Down Expand Up @@ -198,7 +198,7 @@ def test_containerapp_patch_list_and_apply_with_node18_e2e(self, resource_group)
self.cmd(f'configure --defaults group={resource_group}')
patchable_images = self.cmd(f'containerapp patch list').get_output_in_json()
self.assertTrue(len(patchable_images) == 1)
self.assertEquals(patchable_images[0]["oldRunImage"], builder_runtime_image)
self.assertEqual(patchable_images[0]["oldRunImage"], builder_runtime_image)

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply')
Expand Down Expand Up @@ -239,7 +239,7 @@ def test_containerapp_patch_list_and_apply_with_python310_e2e(self, resource_gro
self.cmd(f'configure --defaults group={resource_group}')
patchable_images = self.cmd(f'containerapp patch list').get_output_in_json()
self.assertTrue(len(patchable_images) == 1)
self.assertEquals(patchable_images[0]["oldRunImage"], builder_runtime_image)
self.assertEqual(patchable_images[0]["oldRunImage"], builder_runtime_image)

# Execute and verify patch apply command
self.cmd(f'containerapp patch apply')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_hpc_cache(self, resource_group):
self.cmd('az hpc-cache upgrade-firmware --resource-group {rg} --name {cache_name}', checks=[])

from azure.core.exceptions import ResourceNotFoundError
with self.assertRaisesRegexp(ResourceNotFoundError, 'ResourceNotFound'):
with self.assertRaisesRegex(ResourceNotFoundError, 'ResourceNotFound'):
self.cmd('az hpc-cache update '
'--resource-group {rg} '
'--name "{cache_name}123" '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def test_data_product_e2e(self, resource_group, location, user_id="test@microsof

#List DP
dplistinrg = self.cmd('az network-analytics data-product list --resource-group {group}').get_output_in_json()
self.assertEquals(len(dplistinrg), 1, msg="Data product list should have exactly one element")
self.assertEqual(len(dplistinrg), 1, msg="Data product list should have exactly one element")

#Get DP
self.cmd('az network-analytics data-product show --name {name} --resource-group {group}', checks=[
Expand All @@ -49,8 +49,8 @@ def test_data_product_e2e(self, resource_group, location, user_id="test@microsof

#List User Role
rolelist = self.cmd('az network-analytics data-product list-roles-assignment --data-product-name {name} --resource-group {group}').get_output_in_json()
self.assertEquals(rolelist['count'], 1, msg="Expected role count is 1")
self.assertEquals(rolelist['roleAssignmentResponse'][0]['principalId'], user_id, msg="Principal ID is not matching with the user ID")
self.assertEqual(rolelist['count'], 1, msg="Expected role count is 1")
self.assertEqual(rolelist['roleAssignmentResponse'][0]['principalId'], user_id, msg="Principal ID is not matching with the user ID")

#Remove User Role
self.cmd('az network-analytics data-product remove-user-role --data-product-name {name} --resource-group {group} --data-type-scope " " --principal-id {id} --principal-type user --role reader --role-id " " --user-name " " --role-assignment-id " "')
Expand All @@ -60,7 +60,7 @@ def test_data_product_e2e(self, resource_group, location, user_id="test@microsof

#List User Role
emptyrolelist = self.cmd('az network-analytics data-product list-roles-assignment --data-product-name {name} --resource-group {group}').get_output_in_json()
self.assertEquals(emptyrolelist['count'], 0, msg="role list ia not empty after role is deleted")
self.assertEqual(emptyrolelist['count'], 0, msg="role list ia not empty after role is deleted")

#Delete DP
self.cmd('az network-analytics data-product delete --name {name} --resource-group {group} --yes')
Expand All @@ -70,6 +70,6 @@ def test_data_product_e2e(self, resource_group, location, user_id="test@microsof

#List DP
dplistinrg = self.cmd('az network-analytics data-product list --resource-group {group}').get_output_in_json()
self.assertEquals(len(dplistinrg), 0, msg="Data product list is not empty after deletion")
self.assertEqual(len(dplistinrg), 0, msg="Data product list is not empty after deletion")

pass
pass
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_pre_operations_create_nothing_passed(self, mock_has_value):

self.managed_identity.pre_operations_create(args)

self.assertEquals(
self.assertEqual(
args.identity.type, "None"
) # Expecting None as identity type is passed
self.assertIsNone(
Expand Down
Loading
Loading