<s> from testlinkapi import TestlinkAPIClient , TestLinkHelper <EOL> from testlinkerrors import TestLinkError <EOL> from datetime import date <EOL> class TestLink ( TestlinkAPIClient ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , server_url , key ) : <EOL> """<STR_LIT>""" <EOL> super ( TestLink , self ) . __init__ ( server_url , key ) <EOL> def getTestCaseIDByName ( self , testCaseName , testSuiteName , testProjectName ) : <EOL> """<STR_LIT>""" <EOL> results = super ( TestLink , self ) . getTestCaseIDByName ( testCaseName , testSuiteName , testProjectName ) <EOL> if results [ <NUM_LIT:0> ] . has_key ( "<STR_LIT:message>" ) : <EOL> raise TestLinkError ( results [ <NUM_LIT:0> ] [ "<STR_LIT:message>" ] ) <EOL> elif len ( results ) > <NUM_LIT:1> : <EOL> raise TestLinkError ( "<STR_LIT>" ) <EOL> else : <EOL> if results [ <NUM_LIT:0> ] [ "<STR_LIT:name>" ] == testCaseName : <EOL> return results [ <NUM_LIT:0> ] [ "<STR_LIT:id>" ] <EOL> raise TestLinkError ( "<STR_LIT>" ) <EOL> def reportResult ( self , testResult , testCaseName , testSuiteName , testNotes = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> for data in [ "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ] : <EOL> if not kwargs . has_key ( data ) : <EOL> raise TestLinkError ( "<STR_LIT>" % data ) <EOL> project = self . getTestProjectByName ( kwargs [ "<STR_LIT>" ] ) <EOL> if project [ '<STR_LIT>' ] != '<STR_LIT:1>' : <EOL> raise TestLinkError ( "<STR_LIT>" % kwargs [ "<STR_LIT>" ] ) <EOL> plan = self . getTestPlanByName ( kwargs [ "<STR_LIT>" ] , kwargs [ "<STR_LIT>" ] ) <EOL> if plan [ '<STR_LIT>' ] != '<STR_LIT:1>' or plan [ '<STR_LIT>' ] != '<STR_LIT:1>' : <EOL> raise TestLinkError ( "<STR_LIT>" % kwargs [ "<STR_LIT>" ] ) <EOL> planId = plan [ '<STR_LIT:id>' ] <EOL> build = self . getBuildByName ( kwargs [ "<STR_LIT>" ] , kwargs [ "<STR_LIT>" ] , kwargs [ "<STR_LIT>" ] ) <EOL> if build [ '<STR_LIT>' ] != '<STR_LIT:1>' or build [ '<STR_LIT>' ] != '<STR_LIT:1>' : <EOL> raise TestLinkError ( "<STR_LIT>" % kwargs [ "<STR_LIT>" ] ) <EOL> caseId = self . getTestCaseIDByName ( testCaseName , testSuiteName , kwargs [ "<STR_LIT>" ] ) <EOL> if testResult not in "<STR_LIT>" : <EOL> raise TestLinkError ( "<STR_LIT>" ) <EOL> if testNotes == "<STR_LIT>" : <EOL> today = date . today ( ) <EOL> testNotes = "<STR_LIT>" % today . strftime ( "<STR_LIT>" ) <EOL> elif testNotes == "<STR_LIT:U+0020>" : <EOL> testNotes = "<STR_LIT>" <EOL> print "<STR_LIT>" % testNotes <EOL> results = self . reportTCResult ( caseId , planId , kwargs [ "<STR_LIT>" ] , testResult , testNotes ) <EOL> if results [ <NUM_LIT:0> ] [ "<STR_LIT:message>" ] != "<STR_LIT>" : <EOL> raise TestLinkError ( results [ <NUM_LIT:0> ] [ "<STR_LIT:message>" ] ) <EOL> return results [ <NUM_LIT:0> ] [ '<STR_LIT:id>' ] <EOL> def getTestProjectByName ( self , testProjectName ) : <EOL> """<STR_LIT>""" <EOL> results = super ( TestLink , self ) . getTestProjectByName ( testProjectName ) <EOL> if results [ <NUM_LIT:0> ] . has_key ( "<STR_LIT:message>" ) : <EOL> raise TestLinkError ( results [ <NUM_LIT:0> ] [ "<STR_LIT:message>" ] ) <EOL> return results [ <NUM_LIT:0> ] <EOL> def getTestPlanByName ( self , testProjectName , testPlanName ) : <EOL> """<STR_LIT>""" <EOL> results = super ( TestLink , self ) . getTestPlanByName ( testProjectName , testPlanName ) <EOL> if results [ <NUM_LIT:0> ] . has_key ( "<STR_LIT:message>" ) : <EOL> raise TestLinkError ( results [ <NUM_LIT:0> ] [ "<STR_LIT:message>" ] ) <EOL> return results [ <NUM_LIT:0> ] <EOL> def getBuildByName ( self , testProjectName , testPlanName , buildName ) : <EOL> """<STR_LIT>""" <EOL> plan = self . getTestPlanByName ( testProjectName , testPlanName ) <EOL> builds = self . getBuildsForTestPlan ( plan [ '<STR_LIT:id>' ] ) <EOL> if builds == '<STR_LIT>' : <EOL> raise TestLinkError ( "<STR_LIT>" % ( buildName , testPlanName ) ) <EOL> for build in builds : <EOL> if build [ '<STR_LIT:name>' ] == buildName : <EOL> return build <EOL> raise TestLinkError ( "<STR_LIT>" % ( buildName , testPlanName ) ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> tl_helper = TestLinkHelper ( ) <EOL> tl_helper . setParamsFromArgs ( ) <EOL> myTestLink = tl_helper . connect ( TestLink ) <EOL> print myTestLink <EOL> print myTestLink . about ( ) </s>
