Skip to content

Commit 69f70cf

Browse files
author
Luiko Czub
committed
new api method - createUser #141
1 parent 4e35ad2 commit 69f70cf

File tree

5 files changed

+61
-6
lines changed

5 files changed

+61
-6
lines changed

example/TestLinkExampleGenericApi.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,33 @@
107107
print(myTestLink.connectionInfo())
108108
print("")
109109

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+
113137
# get user information
114138
response = myTestLink.getUserByLogin(myTestUserName)
115139
print("getUserByLogin", response)
@@ -120,7 +144,6 @@
120144
# example asking the api client about methods arguments
121145
print(myTestLink.whatArgs('createTestCase'))
122146

123-
124147
# example handling Response Error Codes
125148
# first check an invalid devKey and than the own one
126149
try:

src/testlink/testlinkapigeneric.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2068,6 +2068,32 @@ def getAllExecutionsResults(self):
20682068
values 0 (false = default) or 1 (true)
20692069
"""
20702070

2071+
# /**
2072+
# * Create a new user
2073+
# *
2074+
# * Restricted to site admin
2075+
# *
2076+
# * @param struct $args
2077+
# * @param string $args["devKey"]
2078+
# * @param string $args["login"]
2079+
# * @param string $args["firstname"]
2080+
# * @param string $args["lastname"]
2081+
# * @param string $args["email"]
2082+
# * @param string $args["password"] - OPTIONAL
2083+
# *
2084+
# *
2085+
# * @return ID the new user if OK, otherwise error structure
2086+
# *
2087+
# * @access public
2088+
# */
2089+
# public function createUser($args) {
2090+
@decoApiCallAddDevKey
2091+
@decoMakerApiCallWithArgs(['login', 'firstname', 'lastname', 'email'],
2092+
['password'])
2093+
def createUser(self):
2094+
""" Create a new user """
2095+
2096+
20712097
#
20722098
# internal methods for general server calls
20732099
#

src/testlink/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@
1717
#
1818
# ------------------------------------------------------------------------
1919

20-
VERSION = '0.8.2-dev139'
20+
VERSION = '0.8.2-dev141'
2121
TL_RELEASE = '1.9.20-fixed_c88e348ce'

test/utest-offline/test_apiClients_whatArgs.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,9 @@ def test_whatArgs_unknownMethods(api_client):
112112
('createPlatform',['<testprojectname>,', '<platformname>,', 'notes=<notes>',
113113
'platformondesign=<platformondesign>',
114114
'platformonexecution=<platformonexecution>']),
115-
('closeBuild', ['<buildid>'])
115+
('closeBuild', ['<buildid>']),
116+
('createUser', ['<login>', '<firstname>', '<lastname>', '<email>',
117+
'password=<password>'])
116118
]
117119

118120
@pytest.mark.parametrize("apiCall, descriptions",

test/utest-online/test_apiCall_equalPositionalArgs.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,10 @@ def test_closeBuild_unknownID(api_client):
469469
with pytest.raises(TLResponseError, match='4000.*40000713'):
470470
api_client.closeBuild(40000713)
471471

472+
def test_createUser_invalidMail(api_client):
473+
with pytest.raises(TLResponseError, match='14003: Email.*seems no good'):
474+
api_client.createUser('myLogin','myFname','myLname', 'myInvalidMail')
475+
472476

473477
# if __name__ == "__main__":
474478
# #import sys;sys.argv = ['', 'Test.testName']

0 commit comments

Comments
 (0)