Skip to content
Draft
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 @@ -11,6 +11,7 @@
from azure.core.exceptions import HttpResponseError

from azure.mgmt.web import WebSiteManagementClient
from azure.mgmt.web.models import Site
from knack.util import CLIError
from azure.cli.core.azclierror import (InvalidArgumentValueError,
MutuallyExclusiveArgumentError,
Expand Down Expand Up @@ -40,6 +41,7 @@
list_startup_logs,
show_startup_log,
create_webapp)
from azure.cli.command_modules.appservice.utils import _rename_server_farm_props

# pylint: disable=line-too-long
from azure.cli.core.profiles import ResourceType
Expand All @@ -61,6 +63,25 @@ class TestWebappMocked(unittest.TestCase):
def setUp(self):
self.client = WebSiteManagementClient(mock.MagicMock(), '123455678')

def test_rename_server_farm_props_handles_mutable_mapping(self):
site = Site(location='westus')
site['serverFarmId'] = '/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Web/serverfarms/plan'

_rename_server_farm_props(site)

self.assertEqual(site['appServicePlanId'], '/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Web/serverfarms/plan')
self.assertNotIn('serverFarmId', site.keys())

def test_rename_server_farm_props_handles_object_attributes(self):
site = types.SimpleNamespace(
server_farm_id='/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Web/serverfarms/plan')

_rename_server_farm_props(site)

self.assertEqual(site.app_service_plan_id,
'/subscriptions/sub/resourceGroups/rg/providers/Microsoft.Web/serverfarms/plan')
self.assertFalse(hasattr(site, 'server_farm_id'))

@mock.patch('azure.cli.command_modules.appservice.custom._update_site_source_control_properties_for_gh_action')
@mock.patch('azure.cli.command_modules.appservice.custom._add_publish_profile_to_github')
@mock.patch('azure.cli.command_modules.appservice.custom.prompt_y_n')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import urllib
import urllib3
import certifi
from collections.abc import MutableMapping
from datetime import datetime

from knack.log import get_logger
Expand Down Expand Up @@ -249,7 +250,11 @@ def _list_app(cli_ctx, resource_group_name=None):
def _rename_server_farm_props(webapp):
# Should be renamed in SDK in a future release
server_farm_id = get_site_server_farm_id(webapp)
setattr(webapp, 'app_service_plan_id', server_farm_id)
if isinstance(webapp, MutableMapping):
webapp["appServicePlanId"] = server_farm_id
webapp.pop("serverFarmId", None)
else:
setattr(webapp, 'app_service_plan_id', server_farm_id)
# Remove server_farm_id if it exists as an attribute (for old SDK compatibility)
if hasattr(webapp, 'server_farm_id'):
try:
Expand Down
Loading