Skip to content

Commit 7a80a08

Browse files
author
Luiko Czub
committed
Merge branch 'setup_distribution-dir'
2 parents b277de1 + 6129d64 commit 7a80a08

15 files changed

+1143
-264
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.project
2+
.pydevproject
3+
.settings/
4+
build/
5+
*.pyc

README.md

+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
TestLink API Python Client
2+
==========================
3+
4+
Copyright 2011-2012
5+
James Stock, Olivier Renault, TestLink-API-Python-client developers
6+
7+
License [unclear License Type]
8+
9+
Introduction
10+
------------
11+
12+
TestLink-API-Python-client is a Python XMLRPC client for the [TestLink API].
13+
14+
It's a brick of Olivier Renault [JinFeng] idea - an interaction of [TestLink],
15+
[Robot Framework] and [Jenkins].
16+
17+
Initially based on the James Stock testlink-api-python-client R7.
18+
19+
20+
Directory Layout
21+
----------------
22+
23+
src/
24+
* Source for TestLink API Python Client
25+
26+
tests/
27+
* Unit Tests for TestLink API Python Client
28+
29+
examples/
30+
* Examples, how to use the TestLink API Python Client
31+
32+
Installation
33+
------------
34+
35+
### Install TestLinkAPI into a virtualenv environment
36+
37+
```
38+
[PYTHON27]\Scripts\virtualenv [PYENV]\testlink
39+
[PYENV]\testlink\Scripts\activate
40+
python setup.py install
41+
```
42+
43+
### Run example with command line arguments
44+
45+
```
46+
[PYENV]\testlink\Scripts\activate
47+
python example\TestLinkExample.py
48+
--server_url http://[YOURSERVER]/testlink/lib/api/xmlrpc.php
49+
--devKey [Users devKey generated by TestLink]
50+
```
51+
52+
### Run unittests with TestLink Server interaction
53+
54+
```
55+
[PYENV]\testlink\Scripts\activate
56+
set TESTLINK_API_PYTHON_SERVER_URL=http://[YOURSERVER]/testlink/lib/api/xmlrpc.php
57+
set TESTLINK_API_PYTHON_DEVKEY=[Users devKey generated by TestLink]
58+
cd test\utest
59+
python -m unittest testlinkapicallservertest testlinkapi_online_test
60+
```
61+
62+
### Run unittests without TestLink Server interaction
63+
64+
```
65+
[PYENV]\testlink\Scripts\activate
66+
cd test\utest
67+
python -m unittest testlinkhelpertest testlinkapi_offline_test
68+
```
69+
70+
71+
Download
72+
--------
73+
74+
see [downloads]
75+
76+
77+
TestLink-API-Python-client developers
78+
-------------------------------------
79+
* [James Stock], [Olivier Renault], kereval.com
80+
* [g4l4drim], [pade], [lczub]
81+
* anyone forgotten?
82+
83+
84+
[unclear License Type]: https://github.com/orenault/TestLink-API-Python-client/issues/4
85+
[JinFeng]: http://www.sqaopen.net/blog/en/?p=63
86+
[TestLink API]: http://www.teamst.org/_tldoc/1.8/phpdoc_api/TestlinkAPI/TestlinkXMLRPCServer.html
87+
[TestLink]: http://www.teamst.org/
88+
[Robot Framework]: http://code.google.com/p/robotframework
89+
[Jenkins]: http://jenkins-ci.org/
90+
[downloads]: https://github.com/lczub/TestLink-API-Python-client/downloads
91+
[Olivier Renault]: https://github.com/orenault/TestLink-API-Python-client
92+
[pade]: https://github.com/pade/TestLink-API-Python-client
93+
[g4l4drim]: https://github.com/g4l4drim/TestLink-API-Python-client
94+
[James Stock]: https://code.google.com/p/testlink-api-python-client/
95+
[lczub]: https://github.com/lczub/TestLink-API-Python-client

TestLinkExample.py renamed to example/TestLinkExample.py

+15-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,23 @@
2626
|
2727
--- 5 automated test steps
2828
"""
29-
import TestLinkAPI
29+
from testlink import TestlinkAPIClient, TestLinkHelper
3030
import sys
3131

32-
myTestLinkServer = "http://YOURSERVER/testlink/lib/api/xmlrpc.php" # YOURSERVER
33-
myDevKey = "" # Put here your devKey
34-
35-
myTestLink = TestLinkAPI.TestlinkAPIClient(myTestLinkServer, myDevKey)
32+
# precondition a)
33+
# SERVEUR_URL and KEY are defined in environment
34+
# TESTLINK_API_PYTHON_SERVER_URL=http://YOURSERVER/testlink/lib/api/xmlrpc.php
35+
# TESTLINK_API_PYTHON_DEVKEY=7ec252ab966ce88fd92c25d08635672b
36+
#
37+
# alternative precondition b)
38+
# SERVEUR_URL and KEY are defined as command line arguments
39+
# python TestLinkExample.py --server_url http://YOURSERVER/testlink/lib/api/xmlrpc.php
40+
# --devKey 7ec252ab966ce88fd92c25d08635672b
41+
tl_helper = TestLinkHelper()
42+
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI.
43+
=> Counts and lists the Projects
44+
=> Create a new Project with the following structure:''')
45+
myTestLink = tl_helper.connect(TestlinkAPIClient)
3646

3747

3848
NEWPROJECT="NEW_PROJECT_API"

setup.py

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#! /usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
# Copyright 2012 ??? , ???
5+
#
6+
# Licensed under ???
7+
#
8+
9+
from os.path import join, dirname
10+
from distutils.core import setup
11+
12+
execfile(join(dirname(__file__), 'src', 'testlink', 'version.py'))
13+
14+
setup(name='TestLink',
15+
version=VERSION,
16+
description='Python XMLRPC client for the TestLink API',
17+
author='James Stock, Olivier Renault, TestLink-API-Python-client developers',
18+
author_email='???, ???, ???',
19+
url='https://github.com/lczub/TestLink-API-Python-client',
20+
license = 'unknown',
21+
package_dir = {'': 'src'},
22+
packages=['testlink'],
23+
)
24+

src/testlink/__init__.py

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#! /usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
# Copyright 2012 TestLink-API-Python-client developers
5+
#
6+
# Licensed under ???
7+
# see https://github.com/orenault/TestLink-API-Python-client/issues/4
8+
9+
10+
from .testlinkerrors import TestLinkError
11+
from .testlinkapi import TestlinkAPIClient
12+
from .testlink import TestLink
13+
from .testlinkhelper import TestLinkHelper

src/testlink/testlink.py

+159
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
#! /usr/bin/python
2+
# -*- coding: UTF-8 -*-
3+
4+
# Copyright 2012 pade (Paul Dassier), TestLink-API-Python-client developers
5+
#
6+
# Licensed under ???
7+
# see https://github.com/orenault/TestLink-API-Python-client/issues/4
8+
9+
from testlinkapi import TestlinkAPIClient, TestLinkHelper
10+
from testlinkerrors import TestLinkError
11+
from datetime import date
12+
13+
14+
class TestLink(TestlinkAPIClient):
15+
"""
16+
TestLink API library
17+
provide a user friendly library, with more robustness and error management
18+
"""
19+
20+
def __init__(self, server_url, key):
21+
"""
22+
Class initialisation
23+
"""
24+
super(TestLink, self).__init__(server_url, key)
25+
26+
def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
27+
"""
28+
Find a test case by its name, by its suite and its project
29+
Suite name must not be duplicate, so only one test case must be found
30+
Return test case id if success
31+
or raise TestLinkError exception with error message in case of error
32+
"""
33+
results = super(TestLink, self).getTestCaseIDByName(testCaseName, testSuiteName, testProjectName)
34+
if results[0].has_key("message"):
35+
raise TestLinkError(results[0]["message"])
36+
elif len(results) > 1:
37+
raise TestLinkError("(getTestCaseIDByName) - Several case test found. Suite name must not be duplicate for the same project")
38+
else:
39+
if results[0]["name"] == testCaseName:
40+
return results[0]["id"]
41+
raise TestLinkError("(getTestCaseIDByName) - Internal server error. Return value is not expected one!")
42+
43+
44+
def reportResult(self, testResult, testCaseName, testSuiteName, testNotes="", **kwargs):
45+
"""
46+
Report results for test case
47+
Arguments are:
48+
- testResult: "p" for passed, "b" for blocked, "f" for failed
49+
- testCaseName: the test case name to report
50+
- testSuiteName: the test suite name that support the test case
51+
- testNotes: optional, if empty will be replace by a default string. To let it blank, just set testNotes to " " characters
52+
- an anonymous dictionnary with followings keys:
53+
- testProjectName: the project to fill
54+
- testPlanName: the active test plan
55+
- buildName: the active build.
56+
Raise a TestLinkError error with the error message in case of trouble
57+
Return the execution id needs to attach files to test execution
58+
"""
59+
60+
# Check parameters
61+
for data in ["testProjectName", "testPlanName", "buildName"]:
62+
if not kwargs.has_key(data):
63+
raise TestLinkError("(reportResult) - Missing key %s in anonymous dictionnary" % data)
64+
65+
# Get project id
66+
project = self.getTestProjectByName(kwargs["testProjectName"])
67+
68+
# Check if project is active
69+
if project['active'] != '1':
70+
raise TestLinkError("(reportResult) - Test project %s is not active" % kwargs["testProjectName"])
71+
72+
# Check test plan name
73+
plan = self.getTestPlanByName(kwargs["testProjectName"], kwargs["testPlanName"])
74+
75+
# Check is test plan is open and active
76+
if plan['is_open'] != '1' or plan['active'] != '1':
77+
raise TestLinkError("(reportResult) - Test plan %s is not active or not open" % kwargs["testPlanName"])
78+
# Memorise test plan id
79+
planId = plan['id']
80+
81+
# Check build name
82+
build = self.getBuildByName(kwargs["testProjectName"], kwargs["testPlanName"], kwargs["buildName"])
83+
84+
# Check if build is open and active
85+
if build['is_open'] != '1' or build['active'] != '1':
86+
raise TestLinkError("(reportResult) - Build %s in not active or not open" % kwargs["buildName"])
87+
88+
# Get test case id
89+
caseId = self.getTestCaseIDByName(testCaseName, testSuiteName, kwargs["testProjectName"])
90+
91+
# Check results parameters
92+
if testResult not in "pbf":
93+
raise TestLinkError("(reportResult) - Test result must be 'p', 'f' or 'b'")
94+
95+
if testNotes == "":
96+
# Builds testNotes if empty
97+
today = date.today()
98+
testNotes = "%s - Test performed automatically" % today.strftime("%c")
99+
elif testNotes == " ":
100+
#No notes
101+
testNotes = ""
102+
103+
print "testNotes: %s" % testNotes
104+
# Now report results
105+
results = self.reportTCResult(caseId, planId, kwargs["buildName"], testResult, testNotes)
106+
# Check errors
107+
if results[0]["message"] != "Success!":
108+
raise TestLinkError(results[0]["message"])
109+
110+
return results[0]['id']
111+
112+
def getTestProjectByName(self, testProjectName):
113+
"""
114+
Return project
115+
A TestLinkError is raised in case of error
116+
"""
117+
results = super(TestLink, self).getTestProjectByName(testProjectName)
118+
if results[0].has_key("message"):
119+
raise TestLinkError(results[0]["message"])
120+
121+
return results[0]
122+
123+
def getTestPlanByName(self, testProjectName, testPlanName):
124+
"""
125+
Return test plan
126+
A TestLinkError is raised in case of error
127+
"""
128+
results = super(TestLink, self).getTestPlanByName(testProjectName, testPlanName)
129+
if results[0].has_key("message"):
130+
raise TestLinkError(results[0]["message"])
131+
132+
return results[0]
133+
134+
def getBuildByName(self, testProjectName, testPlanName, buildName):
135+
"""
136+
Return build corresponding to buildName
137+
A TestLinkError is raised in case of error
138+
"""
139+
plan = self.getTestPlanByName(testProjectName, testPlanName)
140+
builds = self.getBuildsForTestPlan(plan['id'])
141+
142+
# Check if a builds exists
143+
if builds == '':
144+
raise TestLinkError("(getBuildByName) - Builds %s does not exists for test plan %s" % (buildName, testPlanName))
145+
146+
# Search the correct build name in the return builds list
147+
for build in builds:
148+
if build['name'] == buildName:
149+
return build
150+
151+
# No build found with builName name
152+
raise TestLinkError("(getBuildByName) - Builds %s does not exists for test plan %s" % (buildName, testPlanName))
153+
154+
if __name__ == "__main__":
155+
tl_helper = TestLinkHelper()
156+
tl_helper.setParamsFromArgs()
157+
myTestLink = tl_helper.connect(TestLink)
158+
print myTestLink
159+
print myTestLink.about()

0 commit comments

Comments
 (0)