12
12
import xmlrpclib
13
13
import sys
14
14
15
- class Errors (Exception ):
15
+ class TestLinkErrors (Exception ):
16
16
""" Basic error handler
17
17
Return message pass as argument
18
18
"""
@@ -22,9 +22,8 @@ def __init__(self, msg):
22
22
def __str__ (self ):
23
23
return self .__msg
24
24
25
- class TestLinkAPIClient :
25
+ class TestLinkAPIClient ( object ) :
26
26
27
- __VERSION__ = "0.3"
28
27
29
28
def __init__ (self , server_url , devKey ):
30
29
self .server = xmlrpclib .Server (server_url )
@@ -152,9 +151,8 @@ def getTestCaseCustomFieldDesignValue(self, testcaseexternalid, version,
152
151
'details' : str (details )}
153
152
return self .server .tl .getTestCaseCustomFieldDesignValue (argsAPI )
154
153
155
- def __getTestCaseIDByName (self , testCaseName , testSuiteName = None , testProjectName = None ):
156
- """ __getTestCaseIDByName :
157
- Internal function
154
+ def getTestCaseIDByName (self , testCaseName , testSuiteName = None , testProjectName = None ):
155
+ """
158
156
Find a test case by its name
159
157
testSuiteName and testProjectName are optionals arguments
160
158
This function return a list of tests cases
@@ -180,22 +178,6 @@ def __getTestCaseIDByName(self, testCaseName, testSuiteName=None, testProjectNam
180
178
return ret_srv
181
179
182
180
183
- def getTestCaseIDByName (self , testCaseName , testSuiteName , testProjectName ):
184
- """ getTestCaseIDByName :
185
- Find a test case by its name, by its suite and its project
186
- Suite name must not be duplicate, so only one test case must be found
187
- Return (id, None) if success
188
- or (-1, "error message") in case of error
189
- """
190
- results = self .__getTestCaseIDByName (testCaseName , testSuiteName , testProjectName )
191
- if results [0 ].has_key ("message" ):
192
- return (- 1 , results [0 ]["message" ])
193
- elif len (results ) > 1 :
194
- return (- 1 , "(getTestCaseIDByName) - Several case test found. Suite name must not be duplicate for the same project" )
195
- else :
196
- if results [0 ]["name" ] == testCaseName :
197
- return (results [0 ]["id" ], None )
198
- return (- 1 , "(getTestCaseIDByName) - Internal server error. Return value is not expected one!" )
199
181
200
182
201
183
def getTestCasesForTestPlan (self , * args ):
@@ -596,19 +578,35 @@ def __str__(self):
596
578
"""
597
579
return message % self .__VERSION__
598
580
599
- if __name__ == "__main__" :
600
- myTestLinkServer = "http://YOURSERVER/testlink/lib/api/xmlrpc.php" #change
601
- myDevKey = "" # Put here your devKey
602
- myTestLink = TestlinkAPIClient (myTestLinkServer , myDevKey )
603
- print "TestLinkAPIClient - v0.2"
604
- print "@author: Olivier Renault ([email protected] )"
605
- print ""
606
- if myTestLink .checkDevKey () == True :
607
- methodList = [method for method in TestlinkAPIClient .__dict__ ]
608
- for method in methodList :
609
- if method [0 :2 ] != "__" :
610
- print method
611
- print ""
612
- else :
613
- print "Incorrect DevKey."
581
+ class TestLink (TestLinkAPIClient ):
582
+ """
583
+ TestLink API library
584
+ """
585
+
586
+ __VERSION__ = "0.1"
587
+
588
+ def __init__ (self , server_url , key ):
589
+ """
590
+ Class initialisation
591
+ """
592
+
593
+ super (testlink , self ).__init__ (server_url , key )
594
+
595
+ def getTestCaseIDByName (self , testCaseName , testSuiteName , testProjectName ):
596
+ """
597
+ Find a test case by its name, by its suite and its project
598
+ Suite name must not be duplicate, so only one test case must be found
599
+ Return test case id if success
600
+ or raise TestLinkErrors exception with error message in case of error
601
+ """
602
+ results = super (testlink , self ).getTestCaseIDByName (testCaseName , testSuiteName , testProjectName )
603
+ if results [0 ].has_key ("message" ):
604
+ raise TestLinkErrors (results [0 ]["message" ])
605
+ elif len (results ) > 1 :
606
+ raise TestLinkErrors ("(getTestCaseIDByName) - Several case test found. Suite name must not be duplicate for the same project" )
607
+ else :
608
+ if results [0 ]["name" ] == testCaseName :
609
+ return results [0 ]["id" ]
610
+ raise TestLinkErrors ("(getTestCaseIDByName) - Internal server error. Return value is not expected one!" )
611
+
614
612
0 commit comments