def _get_test_cmd(): cli_ctx = DummyCli() loader = AzCommandsLoader(cli_ctx, resource_type=ResourceType.MGMT_COMPUTE) cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = {'resource_type': ResourceType.MGMT_COMPUTE, 'operation_group': 'virtual_machines'} cmd.cli_ctx = cli_ctx return cmd
def _get_test_cmd(): cli_ctx = DummyCli() cli_ctx.data['subscription_id'] = '00000000-0000-0000-0000-000000000000' loader = AzCommandsLoader(cli_ctx, resource_type='Microsoft.AppPlatform') cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = {'resource_type': 'Microsoft.AppPlatform'} cmd.cli_ctx = cli_ctx return cmd
def _get_test_cmd(): from azure.cli.testsdk import TestCli from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand cli_ctx = TestCli() loader = AzCommandsLoader(cli_ctx, resource_type=ResourceType.MGMT_COMPUTE) cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = {'resource_type': ResourceType.MGMT_COMPUTE} cmd.cli_ctx = cli_ctx return cmd
def _get_test_cmd(): from azure.cli.core.mock import DummyCli from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand cli_ctx = DummyCli() loader = AzCommandsLoader(cli_ctx, resource_type=ResourceType.MGMT_APPSERVICE) cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = {'resource_type': ResourceType.MGMT_APPSERVICE} cmd.cli_ctx = cli_ctx return cmd
def test_what_if_exclude_change_types(self, long_running_operation_stub): # Arrange. from azure.cli.core.mock import DummyCli from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand from azure.cli.core.profiles._shared import ResourceType cli_ctx = DummyCli() loader = AzCommandsLoader( cli_ctx, resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = { 'resource_type': ResourceType.MGMT_RESOURCE_RESOURCES } cmd.cli_ctx = cli_ctx WhatIfOperationResult, WhatIfChange, ChangeType = cmd.get_models( 'WhatIfOperationResult', 'WhatIfChange', 'ChangeType') long_running_operation_stub.return_value = WhatIfOperationResult( changes=[ WhatIfChange(resource_id='resource0', change_type=ChangeType.create), WhatIfChange(resource_id='resource1', change_type=ChangeType.modify), WhatIfChange(resource_id='resource2', change_type=ChangeType.ignore), ]) # Act. result = _what_if_deploy_arm_template_core(cmd.cli_ctx, mock.MagicMock(), True, ["create", "igNoRE"]) # Assert. self.assertEqual(1, len(result.changes)) self.assertEqual(ChangeType.modify, result.changes[0].change_type)
_prompt_for_parameters, _load_file_string_or_uri, _what_if_deploy_arm_template_core, deploy_arm_template_at_resource_group, deploy_arm_template_at_subscription_scope, deploy_arm_template_at_management_group, deploy_arm_template_at_tenant_scope, ) from azure.cli.core.mock import DummyCli from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand from azure.cli.core.profiles._shared import ResourceType cli_ctx = DummyCli() loader = AzCommandsLoader(cli_ctx, resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) cmd = AzCliCommand(loader, 'test', None) cmd.command_kwargs = {'resource_type': ResourceType.MGMT_RESOURCE_RESOURCES} cmd.cli_ctx = cli_ctx WhatIfOperationResult, WhatIfChange, ChangeType = cmd.get_models( 'WhatIfOperationResult', 'WhatIfChange', 'ChangeType') def _simulate_no_tty(): from knack.prompting import NoTTYException raise NoTTYException @mock.patch('knack.prompting.verify_is_a_tty', _simulate_no_tty) class TestCustom(unittest.TestCase):
def __init__(self, cli_ctx): self.cli_ctx = cli_ctx self.cmd = AzCliCommand(AzCommandsLoader(cli_ctx), "mock-cmd", None)