@AllowLargeResponse(8192)
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_assign_system_identity(self, resource_group):
    scope = '/subscriptions/{}/resourcegroups/{}'.format(self.get_subscription_id(), resource_group)
    role = 'Reader'
    plan_name = self.create_random_name('web-msi-plan', 20)
    webapp_name = self.create_random_name('web-msi', 20)
    self.cmd('appservice plan create -g {} -n {}'.format(resource_group, plan_name))
    self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, webapp_name, plan_name))
    with mock.patch('azure.cli.core.commands.arm._gen_guid', side_effect=self.create_guid):
        result = self.cmd('webapp identity assign -g {} -n {} --role {} --scope {}'.format(resource_group, webapp_name, role, scope)).get_output_in_json()
        self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=[self.check('principalId', result['principalId'])])
    self.cmd('role assignment list -g {} --assignee {}'.format(resource_group, result['principalId']), checks=[JMESPathCheck('length([])', 1), JMESPathCheck('[0].roleDefinitionName', role)])
    self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=self.check('principalId', result['principalId']))
    self.cmd('webapp identity remove -g {} -n {}'.format(resource_group, webapp_name))
    self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=self.is_empty())
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location=WINDOWS_ASP_LOCATION_WEBAPP)
def test_webapp_assign_system_identity(self, resource_group):
    scope = '/subscriptions/{}/resourcegroups/{}'.format(self.get_subscription_id(), resource_group)
    role = 'Reader'
    plan_name = self.create_random_name('web-msi-plan', 20)
    webapp_name = self.create_random_name('web-msi', 20)
    self.cmd('appservice plan create -g {} -n {}'.format(resource_group, plan_name))
    self.cmd('webapp create -g {} -n {} --plan {}'.format(resource_group, webapp_name, plan_name))
    with mock.patch('azure.cli.core.commands.arm._gen_guid', side_effect=self.create_guid):
        result = self.cmd('webapp identity assign -g {} -n {} --role {} --scope {}'.format(resource_group, webapp_name, role, scope)).get_output_in_json()
        self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=[self.check('principalId', result['principalId'])])
    self.cmd('role assignment list -g {} --assignee {}'.format(resource_group, result['principalId']), checks=[JMESPathCheck('length([])', 1), JMESPathCheck('[0].roleDefinitionName', role)])
    self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=self.check('principalId', result['principalId']))
    self.cmd('webapp identity remove -g {} -n {}'.format(resource_group, webapp_name))
    self.cmd('webapp identity show -g {} -n {}'.format(resource_group, webapp_name), checks=self.is_empty())