class MockCmd: def __init__(self, cli_ctx): self.cli_ctx = cli_ctx self.cmd = AzCliCommand(AzCommandsLoader(cli_ctx), "mock-cmd", None) def supported_api_version( self, resource_type=None, min_api=None, max_api=None, operation_group=None, parameter_name=None, ): return self.cmd.supported_api_version( resource_type=resource_type, min_api=min_api, max_api=max_api, operation_group=operation_group, parameter_name=parameter_name, ) def get_models(self, *attr_args, **kwargs): return self.cmd.get_models(*attr_args, **kwargs)
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)
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 test_file_string_or_uri(self): data = '{ "some": "data here"}' with tempfile.NamedTemporaryFile(delete=False) as tmp: tmp.write(data.encode('utf-8')) tmp.close()
from azure.cli.core.profiles import ResourceType from azure.cli.core.mock import DummyCli from azure.cli.core import AzCommandsLoader from azure.cli.core.commands import AzCliCommand from azure.cli.command_modules.resource._color import Color, ColoredStringBuilder from azure.cli.command_modules.resource._formatters import format_json, format_what_if_operation_result cli_ctx = DummyCli() loader = AzCommandsLoader(cli_ctx, resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) cmd = AzCliCommand(loader, "test", None, resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) WhatIfOperationResult, WhatIfChange, WhatIfPropertyChange, ChangeType, PropertyChangeType = cmd.get_models( "WhatIfOperationResult", "WhatIfChange", "WhatIfPropertyChange", "ChangeType", "PropertyChangeType", ) class TestFormatJson(unittest.TestCase): _colon = ColoredStringBuilder().append(":", Color.RESET).build() _left_square_bracket = ColoredStringBuilder().append("[", Color.RESET).build() _right_square_bracket = ColoredStringBuilder().append("]", Color.RESET).build() def test_leaf(self): test_data = ( ("null", None), ("true", True), ("false", False), ("42", 42), ("42.12345", 42.12345),