1111"""
1212import xmlrpclib
1313import sys
14+ from datetime import date
1415
1516class TestLinkErrors (Exception ):
1617 """ Basic error handler
@@ -373,9 +374,9 @@ def reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
373374 argsAPI = {'devKey' : self .devKey ,
374375 'testcaseid' : testcaseid ,
375376 'testplanid' : testplanid ,
376- 'buildname' :buildname ,
377377 'status' : status ,
378- 'notes' : notes
378+ 'buildname' : buildname ,
379+ 'notes' : str (notes )
379380 }
380381 return self .server .tl .reportTCResult (argsAPI )
381382
@@ -588,18 +589,20 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
588589 raise TestLinkErrors ("(getTestCaseIDByName) - Internal server error. Return value is not expected one!" )
589590
590591
591- def reportResult (self , testResult , testCaseName , testSuiteName , testNotes , ** kwargs ):
592+ def reportResult (self , testResult , testCaseName , testSuiteName , testNotes = "" , ** kwargs ):
592593 """
593594 Report results for test case
594595 Arguments are:
595596 - testResult: "p" for passed, "b" for blocked, "f" for failed
596597 - testCaseName: the test case name to report
597598 - testSuiteName: the test suite name that support the test case
599+ - testNotes: optional, if empty will be replace by a default string. To let it blank, just set testNotes to " " characters
598600 - an anonymous dictionnary with followings keys:
599601 - testProjectName: the project to fill
600602 - testPlanName: the active test plan
601603 - buildName: the active build.
602604 Raise a TestLinkErrors error with the error message in case of trouble
605+ Return the execution id needs to attach files to test execution
603606 """
604607
605608 # Check parameters
@@ -613,29 +616,51 @@ def reportResult(self, testResult, testCaseName, testSuiteName, testNotes, **kwa
613616 # Check if project is active
614617 if project ['active' ] != '1' :
615618 raise TestLinkErrors ("(reportResult) - Test project %s is not active" % kwargs ["testProjectName" ])
616- # Memorize project id
617- projectId = project ['id' ]
618619
619620 # Check test plan name
620621 plan = self .getTestPlanByName (kwargs ["testProjectName" ], kwargs ["testPlanName" ])
621622
622623 # Check is test plan is open and active
623- if results [ 0 ][ 'is_open' ] != '1' or results [ 0 ] ['active' ] != '1' :
624+ if plan [ 'is_open' ] != '1' or plan ['active' ] != '1' :
624625 raise TestLinkErrors ("(reportResult) - Test plan %s is not active or not open" % kwargs ["testPlanName" ])
626+ # Memorise test plan id
627+ planId = plan ['id' ]
625628
629+ # Check build name
630+ build = self .getBuildByName (kwargs ["testProjectName" ], kwargs ["testPlanName" ], kwargs ["buildName" ])
631+
632+ # Check if build is open and active
633+ if build ['is_open' ] != '1' or build ['active' ] != '1' :
634+ raise TestLinkErrors ("(reportResult) - Build %s in not active or not open" % kwargs ["buildName" ])
635+
636+ # Get test case id
637+ caseId = self .getTestCaseIDByName (testCaseName , testSuiteName , kwargs ["testProjectName" ])
626638
627639 # Check results parameters
628- if testResults not in "pbf" :
640+ if testResult not in "pbf" :
629641 raise TestLinkErrors ("(reportResult) - Test result must be 'p', 'f' or 'b'" )
630642
631-
632- results = self .reportTCResult (testCaseName , testSuiteName , testProjectName )
633- #TODO: à terminer
643+ if testNotes == "" :
644+ # Builds testNotes if empty
645+ today = date .today ()
646+ testNotes = "%s - Test performed automatically" % today .strftime ("%c" )
647+ elif testNotes == " " :
648+ #No notes
649+ testNotes = ""
650+
651+ print "testNotes: %s" % testNotes
652+ # Now report results
653+ results = self .reportTCResult (caseId , planId , kwargs ["buildName" ], testResult , testNotes )
654+ # Check errors
655+ if results [0 ]["message" ] != "Success!" :
656+ raise TestLinkErrors (results [0 ]["message" ])
657+
658+ return results [0 ]['id' ]
634659
635660 def getTestProjectByName (self , testProjectName ):
636661 """
637662 Return project
638- A TestLinkError is raised in case of error
663+ A TestLinkErrors is raised in case of error
639664 """
640665 results = super (TestLink , self ).getTestProjectByName (testProjectName )
641666 if results [0 ].has_key ("message" ):
@@ -650,6 +675,28 @@ def getTestPlanByName(self, testProjectName, testPlanName):
650675 """
651676 results = super (TestLink , self ).getTestPlanByName (testProjectName , testPlanName )
652677 if results [0 ].has_key ("message" ):
653- raise TestLinkErrors (results [0 ]. ["message" ])
678+ raise TestLinkErrors (results [0 ]["message" ])
654679
655680 return results [0 ]
681+
682+ def getBuildByName (self , testProjectName , testPlanName , buildName ):
683+ """
684+ Return build corresponding to buildName
685+ A TestLinkErrors is raised in case of error
686+ """
687+ plan = self .getTestPlanByName (testProjectName , testPlanName )
688+ builds = self .getBuildsForTestPlan (plan ['id' ])
689+
690+ # Check if a builds exists
691+ if builds == '' :
692+ raise TestLinkErrors ("(getBuildsByName) - Builds %s does not exists for test plan %s" % (buildsName , testPlanName ))
693+
694+ # Search the correct build name in the return builds list
695+ for build in builds :
696+ if build ['name' ] == buildName :
697+ return build
698+
699+ # No build found with builName name
700+ raise TestLinkErrors ("(getBuildsByName) - Builds %s does not exists for test plan %s" % (buildsName , testPlanName ))
701+
702+
0 commit comments