Skip to content

Commit

Permalink
Fixing error message from API in case of invalid user license type (#…
Browse files Browse the repository at this point in the history
…554)

* Fixing error message from API in case of invalid user license type

* Updating recording

* Pylint fix
  • Loading branch information
ishitam8 authored Apr 25, 2019
1 parent ebc3d97 commit de2a890
Show file tree
Hide file tree
Showing 4 changed files with 316 additions and 224 deletions.
21 changes: 10 additions & 11 deletions azure-devops/azext_devops/dev/team/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ def update_user_entitlement(user, license_type, organization=None, detect=None):
if '@' in user:
user = resolve_identity_as_id(user, organization)
client = get_member_entitlement_management_client(organization)
try:
user_entitlement_update = client.update_user_entitlement(document=patch_document, user_id=user)
return user_entitlement_update.user_entitlement
except Exception:
raise CLIError('Invalid license type.')
user_entitlement_update = client.update_user_entitlement(document=patch_document, user_id=user)
if user_entitlement_update.is_success is False and \
user_entitlement_update.operation_results[0].errors[0] is not None:
raise CLIError(user_entitlement_update.operation_results[0].errors[0]['value'])
return user_entitlement_update.user_entitlement


def add_user_entitlement(email_id, license_type, send_email_invite='true', organization=None, detect=None):
Expand All @@ -99,12 +99,11 @@ def add_user_entitlement(email_id, license_type, send_email_invite='true', organ
value['user'] = graph_user
patch_document = []
patch_document.append(_create_patch_operation('add', '', value))
try:
user_entitlement_details = client.update_user_entitlements(document=patch_document,
do_not_send_invite_for_new_users=do_not_send_invite)
return user_entitlement_details.results[0].result
except Exception:
raise CLIError('Invalid license type.')
user_entitlement = client.update_user_entitlements(document=patch_document,
do_not_send_invite_for_new_users=do_not_send_invite)
if user_entitlement.have_results_succeeded is False and user_entitlement.results[0].errors[0] is not None:
raise CLIError(user_entitlement.results[0].errors[0]['value'])
return user_entitlement.results[0].result


def _create_patch_operation(op, path, value):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,7 @@ class UserEntitlementOperationResult(Model):
"""

_attribute_map = {
'errors': {'key': 'errors', 'type': '[{ key: int; value: str }]'},
'errors': {'key': 'errors', 'type': 'object'},
'is_success': {'key': 'isSuccess', 'type': 'bool'},
'result': {'key': 'result', 'type': 'UserEntitlement'},
'user_id': {'key': 'userId', 'type': 'str'}
Expand Down
508 changes: 298 additions & 210 deletions tests/recordings/test_devops_user_command_addUpdateListShowRemove.yaml

Large diffs are not rendered by default.

9 changes: 7 additions & 2 deletions tests/test_devopsUserTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import time
import unittest

from knack.util import CLIError
from azure.cli.testsdk import ScenarioTest
from azure_devtools.scenario_tests import AllowLargeResponse
from .utilities.helper import disable_telemetry, set_authentication, get_test_org_from_env_variable
Expand Down Expand Up @@ -59,7 +59,12 @@ def test_devops_user_command_addUpdateListShowRemove(self):
# update user
# can't verify this for organizations created by microsoft account, since access level type is always earlyAdopter
user_update_response = self.cmd('az devops user update -o json --detect off --user ' + _TEST_EMAIL_ID + ' --license-type express').get_output_in_json()
assert user_add_response['user']['mailAddress'] == _TEST_EMAIL_ID
assert user_update_response['user']['mailAddress'] == _TEST_EMAIL_ID

# Error message check in case of invalid license type.
with self.assertRaises(CLIError) as user_update_except:
user_update = self.cmd('az devops user update -o json --detect off --user ' + _TEST_EMAIL_ID + ' --license-type none').get_output_in_json()
self.assertEqual(str(user_update_except.exception), 'VSS012024: Organization user cannot be assigned a None license.')

finally:
if user_id is not None:
Expand Down

0 comments on commit de2a890

Please sign in to comment.