|
12 | 12 | from knack.util import CLIError |
13 | 13 | from azure.cli.core.azclierror import (InvalidArgumentValueError, |
14 | 14 | MutuallyExclusiveArgumentError, |
15 | | - AzureResponseError) |
| 15 | + AzureResponseError, |
| 16 | + ArgumentUsageError) |
16 | 17 | from azure.cli.command_modules.appservice.custom import (set_deployment_user, |
17 | 18 | update_git_token, add_hostname, |
18 | 19 | update_site_configs, |
|
33 | 34 | add_github_actions, |
34 | 35 | update_app_settings, |
35 | 36 | update_application_settings_polling, |
36 | | - update_webapp) |
| 37 | + update_webapp, |
| 38 | + create_webapp) |
37 | 39 |
|
38 | 40 | # pylint: disable=line-too-long |
39 | 41 | from azure.cli.core.profiles import ResourceType |
@@ -436,6 +438,36 @@ def test_valid_linux_create_options(self): |
436 | 438 | self.assertFalse(validate_container_app_create_options(None, None, test_multi_container_config, None)) |
437 | 439 | self.assertFalse(validate_container_app_create_options(None, None, None, None)) |
438 | 440 |
|
| 441 | + @mock.patch('azure.cli.command_modules.appservice.custom.web_client_factory', autospec=True) |
| 442 | + @mock.patch('azure.cli.command_modules.appservice.custom._StackRuntimeHelper', autospec=True) |
| 443 | + @mock.patch('azure.cli.command_modules.appservice.custom.get_site_availability', autospec=True) |
| 444 | + def test_linux_webapp_create_no_runtime_raises_error(self, get_site_avail_mock, |
| 445 | + stack_helper_mock, web_client_mock): |
| 446 | + cmd_mock = _get_test_cmd() |
| 447 | + SiteConfig, SkuDescription, NameValuePair = cmd_mock.get_models( |
| 448 | + 'SiteConfig', 'SkuDescription', 'NameValuePair') |
| 449 | + cmd_mock.get_models = mock.MagicMock(return_value=(SiteConfig, SkuDescription, NameValuePair)) |
| 450 | + |
| 451 | + # Mock a Linux plan (reserved=True) |
| 452 | + plan_info = mock.MagicMock() |
| 453 | + plan_info.reserved = True |
| 454 | + plan_info.location = 'eastus' |
| 455 | + plan_info.id = '/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Web/serverfarms/plan' |
| 456 | + plan_info.sku = SkuDescription(name='F1') |
| 457 | + web_client_mock.return_value.app_service_plans.get.return_value = plan_info |
| 458 | + |
| 459 | + # Mock site availability (new app name) |
| 460 | + name_validation = mock.MagicMock() |
| 461 | + name_validation.name_available = True |
| 462 | + get_site_avail_mock.return_value = name_validation |
| 463 | + |
| 464 | + with self.assertRaises(ArgumentUsageError) as context: |
| 465 | + create_webapp(cmd_mock, 'test-rg', 'test-app', 'test-plan') |
| 466 | + |
| 467 | + self.assertIn('Creating a Linux webapp requires one of the following', str(context.exception)) |
| 468 | + self.assertIn('--runtime', str(context.exception)) |
| 469 | + self.assertIn('--os-type linux', str(context.exception)) |
| 470 | + |
439 | 471 | @mock.patch('azure.cli.command_modules.appservice.custom._verify_hostname_binding', autospec=True) |
440 | 472 | @mock.patch('azure.cli.command_modules.appservice.custom.web_client_factory', autospec=True) |
441 | 473 | @mock.patch('azure.cli.command_modules.appservice.custom._generic_site_operation', autospec=True) |
|
0 commit comments