Dev Key for Python users

Discussion and information for XML-RPC interface.

Moderators: Amaradana, TurboPT, TL Developers

Dev Key for Python users

Postby sfunk » Mon Oct 27, 2008 11:38 pm

How do I find out my user's Dev key so I can use the API?
sfunk
TestLink user
 
Posts: 8
Joined: Fri Oct 10, 2008 1:22 am

Answered myself / found a defect in Python code

Postby sfunk » Thu Oct 30, 2008 3:47 am

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
sfunk
TestLink user
 
Posts: 8
Joined: Fri Oct 10, 2008 1:22 am

The name of the database?

Postby SQADude » Mon Feb 01, 2010 6:08 am

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.
SQADude
TestLink user
 
Posts: 9
Joined: Wed Jan 20, 2010 4:31 am

Postby bmahe » Mon Feb 01, 2010 7:26 pm

Why not going through the UI?
It is available on the "Personal" menu, just next to Logout. From there you can generate or access your dev key.

Just make sure you enable the api in config/custom_config
bmahe
TestLink user
 
Posts: 3
Joined: Fri Jan 15, 2010 3:25 am
Location: San Francisco

Re: do you need to do more than just provide a valid devKey?

Postby SQADude » Mon Feb 01, 2010 10:50 pm

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"


sfunk and others:

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?
SQADude
TestLink user
 
Posts: 9
Joined: Wed Jan 20, 2010 4:31 am

Postby djazz » Thu Feb 04, 2010 2:27 pm

it looks like your code should not match with what is it in your db.
Can you show us the code you use and the result of : "select * from users;" in your db ?
djazz
TestLink user
 
Posts: 8
Joined: Thu Feb 04, 2010 10:54 am

Postby SQADude » Tue Feb 09, 2010 7:32 pm

This is the output from the SQL DB:

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  |
+----+-------+----------------------------------+---------+------------------+----------+---------------+--------+------------------------+--------+------------+



I blocked out the password, email, and other columns for privacy's sake....


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?
SQADude
TestLink user
 
Posts: 9
Joined: Wed Jan 20, 2010 4:31 am


Return to XML-RPC API



Who is online

Users browsing this forum: No registered users and 2 guests

cron