Skip to content

Commit

Permalink
new api method - createUser #141
Browse files Browse the repository at this point in the history
  • Loading branch information
Luiko Czub committed Oct 24, 2021
1 parent 4e35ad2 commit 69f70cf
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 6 deletions.
31 changes: 27 additions & 4 deletions example/TestLinkExampleGenericApi.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,33 @@
print(myTestLink.connectionInfo())
print("")

# CHANGE this name into a valid account, known in your TL application
myTestUserName="pyTLapi"
myTestUserName2="admin"
def checkUser(name1, name2):
""" checks if user NAME1_NAME2 exists
when not , user will be created
returns username + userid
"""

login = "{}_{}".format(name1, name2)
mail = "{}.{}@example.com".format(name1, name2)
try:
response = myTestLink.getUserByLogin(login)
userID = response[0]['dbID']
except TLResponseError as tl_err:
if tl_err.code == 10000:
# Cannot Find User Login - create new user
userID = myTestLink.createUser(login, name1, name2, mail)
else:
# seems to be another response failure - we forward it
raise

return login, userID

# ensure tester and expert users exists
myTestUserName, myTestUser1_ID=checkUser("myTester", "pyTLapi")
print("checkUser", myTestUserName, myTestUser1_ID)
myTestUserName2, myTestUser2_ID=checkUser("myExpert", "pyTLapi")
print("checkUser", myTestUserName2, myTestUser2_ID)

# get user information
response = myTestLink.getUserByLogin(myTestUserName)
print("getUserByLogin", response)
Expand All @@ -120,7 +144,6 @@
# example asking the api client about methods arguments
print(myTestLink.whatArgs('createTestCase'))


# example handling Response Error Codes
# first check an invalid devKey and than the own one
try:
Expand Down
26 changes: 26 additions & 0 deletions src/testlink/testlinkapigeneric.py
Original file line number Diff line number Diff line change
Expand Up @@ -2068,6 +2068,32 @@ def getAllExecutionsResults(self):
values 0 (false = default) or 1 (true)
"""

# /**
# * Create a new user
# *
# * Restricted to site admin
# *
# * @param struct $args
# * @param string $args["devKey"]
# * @param string $args["login"]
# * @param string $args["firstname"]
# * @param string $args["lastname"]
# * @param string $args["email"]
# * @param string $args["password"] - OPTIONAL
# *
# *
# * @return ID the new user if OK, otherwise error structure
# *
# * @access public
# */
# public function createUser($args) {
@decoApiCallAddDevKey
@decoMakerApiCallWithArgs(['login', 'firstname', 'lastname', 'email'],
['password'])
def createUser(self):
""" Create a new user """


#
# internal methods for general server calls
#
Expand Down
2 changes: 1 addition & 1 deletion src/testlink/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
#
# ------------------------------------------------------------------------

VERSION = '0.8.2-dev139'
VERSION = '0.8.2-dev141'
TL_RELEASE = '1.9.20-fixed_c88e348ce'
4 changes: 3 additions & 1 deletion test/utest-offline/test_apiClients_whatArgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ def test_whatArgs_unknownMethods(api_client):
('createPlatform',['<testprojectname>,', '<platformname>,', 'notes=<notes>',
'platformondesign=<platformondesign>',
'platformonexecution=<platformonexecution>']),
('closeBuild', ['<buildid>'])
('closeBuild', ['<buildid>']),
('createUser', ['<login>', '<firstname>', '<lastname>', '<email>',
'password=<password>'])
]

@pytest.mark.parametrize("apiCall, descriptions",
Expand Down
4 changes: 4 additions & 0 deletions test/utest-online/test_apiCall_equalPositionalArgs.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,10 @@ def test_closeBuild_unknownID(api_client):
with pytest.raises(TLResponseError, match='4000.*40000713'):
api_client.closeBuild(40000713)

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


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

0 comments on commit 69f70cf

Please sign in to comment.