Skip to content

Commit 52fb491

Browse files
authored
Merge pull request #47 from draios/improve-teams-example
Make User/Team Management example fail more often
2 parents 72e9401 + 61e3c5a commit 52fb491

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

examples/user_team_mgmt.py

+28-13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/usr/bin/env python
22
#
3-
# This example shows the different aspects of user/team management
3+
# This example shows the different aspects of user/team management.
44
#
55

66
import os
@@ -26,49 +26,64 @@
2626
team_name = sys.argv[2]
2727
user_name = sys.argv[3]
2828

29-
print 'Trying to invite a user ', user_name
29+
print 'Trying to invite a user:', user_name
3030
res = sdclient.create_user_invite(user_name)
3131
if res[0] == False:
32-
print 'User creation failed: ', res[1]
32+
if res[1] == 'user ' + user_name + ' already exists':
33+
print 'User creation failed because', user_name ,'already exists. Continuing.'
34+
else:
35+
print 'User creation failed:', res[1], '. Exiting.'
36+
sys.exit(1)
3337
else:
3438
print 'User creation succeeded'
3539

36-
print 'Now trying to create a team with name ', team_name
40+
# Possible failures on Team creation might include having reached the
41+
# max limit on Teams for this customer account or if the Team by that
42+
# name already exists. Since a previous successful run of this test
43+
# would have deleted the Team by the same name, and we need to be able
44+
# to configure Teams for this test to pass, we'll treat both types of
45+
# error as a genuine fail of the test.
46+
print 'Now trying to create a team with name:', team_name
3747
res = sdclient.create_team(team_name)
3848
if res[0] == False:
39-
print 'Team creation failed: ', res[1]
49+
print 'Team creation failed:', res[1], '. Exiting.'
50+
sys.exit(1)
4051
else:
4152
print 'Team creation succeeded.', res[1]
4253

43-
print 'Now trying to find team with name ', team_name
54+
print 'Now trying to find team with name:', team_name
4455
res = sdclient.get_team(team_name)
4556
if res[0] == False:
46-
print 'Could not get team info'
57+
print 'Could not get team info:', res[1], '. Exiting.'
58+
sys.exit(1)
4759
else:
4860
print 'Team fetch succeeded'
4961

50-
print 'Now trying to edit team ', team_name
62+
print 'Now trying to edit team:', team_name
5163
memberships = {
5264
'admin@draios.com': 'ROLE_TEAM_MANAGER',
5365
'john-doe@sysdig.com': 'ROLE_TEAM_READ'
5466
}
5567
res = sdclient.edit_team(team_name, description='Nextgen2', memberships=memberships)
5668
if res[0] == False:
57-
print 'Could not edit team ', res[1]
69+
print 'Could not edit team:', res[1], '. Exiting.'
70+
sys.exit(1)
5871
else:
5972
print 'Edited team to change description and add users'
6073

61-
print 'Now trying to edit user ', user_name
74+
print 'Now trying to edit user:', user_name
6275
res = sdclient.edit_user(user_name, firstName='Just', lastName='Edited3', systemRole='ROLE_CUSTOMER')
6376
if res[0] == False:
64-
print 'Could not edit user: ', res[1]
77+
print 'Could not edit user:', res[1], '. Exiting.'
78+
sys.exit(1)
6579
else:
6680
print 'Edit user succeeded'
6781

68-
print 'Now trying to delete the team ', team_name
82+
print 'Now trying to delete the team:', team_name
6983
res = sdclient.delete_team(team_name)
7084
if res[0] == False:
71-
print 'Could not delete team: ', res[1]
85+
print 'Could not delete team:', res[1], '. Exiting.'
86+
sys.exit(1)
7287
else:
7388
print 'Delete team succeeded'
7489

0 commit comments

Comments
 (0)