|
107 | 107 | print(myTestLink.connectionInfo())
|
108 | 108 | print("")
|
109 | 109 |
|
110 |
| -# CHANGE this name into a valid account, known in your TL application |
111 |
| -myTestUserName="pyTLapi" |
112 |
| -myTestUserName2="admin" |
| 110 | +def checkUser(name1, name2): |
| 111 | + """ checks if user NAME1_NAME2 exists |
| 112 | + when not , user will be created |
| 113 | + returns username + userid |
| 114 | + """ |
| 115 | + |
| 116 | + login = "{}_{}".format(name1, name2) |
| 117 | + mail = "{}.{}@example.com".format(name1, name2) |
| 118 | + try: |
| 119 | + response = myTestLink.getUserByLogin(login) |
| 120 | + userID = response[0]['dbID'] |
| 121 | + except TLResponseError as tl_err: |
| 122 | + if tl_err.code == 10000: |
| 123 | + # Cannot Find User Login - create new user |
| 124 | + userID = myTestLink.createUser(login, name1, name2, mail) |
| 125 | + else: |
| 126 | + # seems to be another response failure - we forward it |
| 127 | + raise |
| 128 | + |
| 129 | + return login, userID |
| 130 | + |
| 131 | +# ensure tester and expert users exists |
| 132 | +myTestUserName, myTestUser1_ID=checkUser("myTester", "pyTLapi") |
| 133 | +print("checkUser", myTestUserName, myTestUser1_ID) |
| 134 | +myTestUserName2, myTestUser2_ID=checkUser("myExpert", "pyTLapi") |
| 135 | +print("checkUser", myTestUserName2, myTestUser2_ID) |
| 136 | + |
113 | 137 | # get user information
|
114 | 138 | response = myTestLink.getUserByLogin(myTestUserName)
|
115 | 139 | print("getUserByLogin", response)
|
|
120 | 144 | # example asking the api client about methods arguments
|
121 | 145 | print(myTestLink.whatArgs('createTestCase'))
|
122 | 146 |
|
123 |
| - |
124 | 147 | # example handling Response Error Codes
|
125 | 148 | # first check an invalid devKey and than the own one
|
126 | 149 | try:
|
|
0 commit comments