Dev Key for Python users
Moderators: Amaradana, TurboPT, TL Developers
Dev Key for Python users
How do I find out my user's Dev key so I can use the API?
Answered myself / found a defect in Python code
In order to get a devKey I had to log into mysql and add one to my user account myself see SQL below:
UPDATE users SET script_key="11111111111111111111111111111111" WHERE id="6"
There is also a defect in the Python code where the disctionary names do not align with the dictionary in TestlinkXMLRPCServer:
EXAMPLE NAMES in all Sample Code:
def reportTCResult(self, tcid, tpid, status):
data = {"devKey":self.devKey, "tcid":tcid, "tpid":tpid, "status":status}
return self.server.tl.reportTCResult(data)
ACTUAL DICTIONARY NAMES:
Parameters:
struct $args:
string $args["devKey"]:
int $args["testcaseid"]:
int $args["testplanid"]:
string $args["status"]: - status is $validStatusList
int $args["buildid"]: - optional
string $args["notes"]: - optional
bool $args["guess"]: - optional
UPDATE users SET script_key="11111111111111111111111111111111" WHERE id="6"
There is also a defect in the Python code where the disctionary names do not align with the dictionary in TestlinkXMLRPCServer:
EXAMPLE NAMES in all Sample Code:
def reportTCResult(self, tcid, tpid, status):
data = {"devKey":self.devKey, "tcid":tcid, "tpid":tpid, "status":status}
return self.server.tl.reportTCResult(data)
ACTUAL DICTIONARY NAMES:
Parameters:
struct $args:
string $args["devKey"]:
int $args["testcaseid"]:
int $args["testplanid"]:
string $args["status"]: - status is $validStatusList
int $args["buildid"]: - optional
string $args["notes"]: - optional
bool $args["guess"]: - optional
The name of the database?
sfunk,
could you (or anyone else?) tell me the database that I need to edit to be able to get a devKey for the API?
I can get by with simple MySQL commands but I don't know the names of the database tables of Testlink's DB.
Anyone know them?
Thanx.
could you (or anyone else?) tell me the database that I need to edit to be able to get a devKey for the API?
I can get by with simple MySQL commands but I don't know the names of the database tables of Testlink's DB.
Anyone know them?
Thanx.
Re: do you need to do more than just provide a valid devKey?
sfunk and others:sfunk wrote:In order to get a devKey I had to log into mysql and add one to my user account myself see SQL below:
UPDATE users SET script_key="11111111111111111111111111111111" WHERE id="6"
I edited the users DB for testlink and added a string for the "script_key" field in the database. "script_key" was NULL until I made the changes.
I used the same string for the devKey in the testlink Client in Python that I did for the "script_key" field.
But I get an error when I do a simple getProjects() call:
"Can not authenticate client: invalid developer key", code: 2000 in the "results" dictionary.
Is there more I need to do for authentication to use the Testlink API?
This is the output from the SQL DB:
I blocked out the password, email, and other columns for privacy's sake....
My code is this:
The output when I run it is:
> python TestlinkClient.py
Testlink API Version: 1.0 Beta 5 initially written by Asiel Brumfield
with contributions by TestLink development Team
retval: [{'message': 'Can not authenticate client: invalid developer key', 'code': 2000}]
The script_key field in the users table in MySQL is a varchar(32) so it shouldn't matter if the script key is 9 char or 32 char, should it?
Code: Select all
mysql> select * from users;
+----+-------+----------------------------------+---------+------------------+----------+---------------+--------+------------------------+--------+------------+
| id | login | password | role_id | email | first | last | locale | default_testproject_id | active | script_key |
+----+-------+----------------------------------+---------+------------------+----------+---------------+--------+------------------------+--------+------------+
| 1 | admin | ******************************** | 8 | *************** | Testlink | Administrator | en_GB | NULL | 1 | Raven5669 |
| 2 | *** | ******************************** | 8 | *************** | ***** | ***** | en_GB | NULL | 1 | NULL |
| 3 | **** | ******************************** | 6 | *************** | ***** | ***** | en_GB | NULL | 1 | NULL |
| 4 | ***** | ******************************** | 5 | *************** | ***** | ***** | en_US | NULL | 1 | NULL |
| 5 | *** | ******************************** | 5 | *************** | ***** | ***** | en_GB | NULL | 1 | NULL |
| 6 | root | ******************************** | 8 | *************** | ***** | ***** | en_US | NULL | 1 | Raven5669 |
+----+-------+----------------------------------+---------+------------------+----------+---------------+--------+------------------------+--------+------------+
My code is this:
Code: Select all
Testlink API Sample Python Client implementation
"""
import xmlrpclib
class TestlinkAPIClient:
# substitute your server URL Here
SERVER_URL = "****************************"
def __init__(self, devKey):
self.server = xmlrpclib.Server(self.SERVER_URL)
self.devKey = devKey
def reportTCResult(self, tcid, tpid, status):
data = {"devKey":self.devKey, "tcid":tcid, "tpid":tpid, "status":status}
return self.server.tl.reportTCResult(data)
def getInfo(self):
return self.server.tl.about()
def sayHello (self):
return self.server.tl.sayHello()
def getProjects (self, devKey):
return self.server.tl.getProjects(devKey)
if __name__ == '__main__':
# devKey = "f2a979d533cdd9761434bba60a88e4d8"
devKey = "Raven5669"
# devKey = "12345678901234567890123456789012"
# devKey = ""
# substitute your Dev Key Here
client = TestlinkAPIClient (devKey)
# get info about the server
print client.getInfo()
# result = client.
# Substitute for tcid and tpid that apply to your project
# result = client.reportTCResult(1132, 56646, "p")
# Typically you'd want to validate the result here and probably do something more useful with it
## print "reportTCResult result was: %s" %(result)
## retval = client.sayHello()
## print "reportTCResult result was: %s" %(result)
## retval = client.sayHello()
retval = client.getProjects(devKey)
print 'retval: ', retval
The output when I run it is:
> python TestlinkClient.py
Testlink API Version: 1.0 Beta 5 initially written by Asiel Brumfield
with contributions by TestLink development Team
retval: [{'message': 'Can not authenticate client: invalid developer key', 'code': 2000}]
The script_key field in the users table in MySQL is a varchar(32) so it shouldn't matter if the script key is 9 char or 32 char, should it?