File: test_devopsUserTest.py

package info (click to toggle)
azure-devops-cli-extension 1.0.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 22,680 kB
  • sloc: python: 160,797; xml: 198; sh: 61; makefile: 56
file content (76 lines) | stat: -rw-r--r-- 4,141 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import unittest
from knack.util import CLIError
from azure_devtools.scenario_tests import AllowLargeResponse
from .utilities.helper import DevopsScenarioTest, disable_telemetry, set_authentication, get_test_org_from_env_variable

DEVOPS_CLI_TEST_ORGANIZATION = get_test_org_from_env_variable() or 'https://dev.azure.com/v-anvashist0376'
_TEST_EMAIL_ID = 'new_user_test@outlook.com'


class TestUser(DevopsScenarioTest):
    @AllowLargeResponse(size_kb=3072)
    @disable_telemetry
    @set_authentication
    def test_devops_user_command_addUpdateListShowRemove(self):
        self.cmd('az devops configure --defaults organization=' +  DEVOPS_CLI_TEST_ORGANIZATION)
        try:
            user_id = None
            # check user list before adding the user
            list_response = self.cmd('az devops user list -o json --detect false').get_output_in_json()
            assert list_response.get('members') is not None
            user_list_response = list_response['members']
            assert len(user_list_response) > 0
            user_id_found = False
            for item in user_list_response :
                if item['user']['mailAddress'] == _TEST_EMAIL_ID:
                    user_id_found = True
            # Remove the user if already present in the organization.
            if user_id_found == True:
                user_remove_response = self.cmd('az devops user remove --user ' + _TEST_EMAIL_ID + ' -o json --detect false -y')

            #add user
            user_add_response = self.cmd('az devops user add -o json --detect false --email-id ' + _TEST_EMAIL_ID + ' --license-type stakeholder').get_output_in_json()
            user_id = user_add_response['id']
            assert user_add_response['user']['mailAddress'] == _TEST_EMAIL_ID

            # check if user is present in list response
            list_response = self.cmd('az devops user list -o json --detect false').get_output_in_json()
            assert list_response.get('members') is not None
            user_list_response = list_response['members']
            assert len(user_list_response) > 1
            user_id_found = False
            for item in user_list_response :
                if item['user']['mailAddress'] == _TEST_EMAIL_ID:
                    user_id_found = True
            assert user_id_found == True

            # show user details
            user_show_response = self.cmd('az devops user show -o json --detect false --user ' + _TEST_EMAIL_ID).get_output_in_json()
            assert user_show_response['id'] == user_id
            assert user_show_response['user']['mailAddress'] == _TEST_EMAIL_ID

            # 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 false --user ' + _TEST_EMAIL_ID + ' --license-type express').get_output_in_json()
            assert user_update_response['user']['mailAddress'] == _TEST_EMAIL_ID

     
        finally:
            if user_id is not None:
                user_remove_response = self.cmd('az devops user remove --user ' + _TEST_EMAIL_ID + ' -o json --detect false -y')
                
                # check user list
                list_response = self.cmd('az devops user list -o json --detect false').get_output_in_json()
                assert list_response.get('members') is not None
                user_list_response = list_response['members']
                assert len(user_list_response) > 0
                user_id_found = False
                for item in user_list_response :
                    if item['user']['mailAddress'] == _TEST_EMAIL_ID:
                        user_id_found = True
                assert user_id_found == False