1212import xmlrpclib
1313import sys
1414
15- class Errors (Exception ):
15+ class TestLinkErrors (Exception ):
1616 """ Basic error handler
1717 Return message pass as argument
1818 """
@@ -22,9 +22,8 @@ def __init__(self, msg):
2222 def __str__ (self ):
2323 return self .__msg
2424
25- class TestLinkAPIClient :
25+ class TestLinkAPIClient ( object ) :
2626
27- __VERSION__ = "0.3"
2827
2928 def __init__ (self , server_url , devKey ):
3029 self .server = xmlrpclib .Server (server_url )
@@ -152,9 +151,8 @@ def getTestCaseCustomFieldDesignValue(self, testcaseexternalid, version,
152151 'details' : str (details )}
153152 return self .server .tl .getTestCaseCustomFieldDesignValue (argsAPI )
154153
155- def __getTestCaseIDByName (self , testCaseName , testSuiteName = None , testProjectName = None ):
156- """ __getTestCaseIDByName :
157- Internal function
154+ def getTestCaseIDByName (self , testCaseName , testSuiteName = None , testProjectName = None ):
155+ """
158156 Find a test case by its name
159157 testSuiteName and testProjectName are optionals arguments
160158 This function return a list of tests cases
@@ -180,22 +178,6 @@ def __getTestCaseIDByName(self, testCaseName, testSuiteName=None, testProjectNam
180178 return ret_srv
181179
182180
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!" )
199181
200182
201183 def getTestCasesForTestPlan (self , * args ):
@@ -596,19 +578,35 @@ def __str__(self):
596578"""
597579 return message % self .__VERSION__
598580
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+
614612
0 commit comments