11
11
"""
12
12
import xmlrpclib
13
13
import sys
14
+ from datetime import date
14
15
15
16
class TestLinkErrors (Exception ):
16
17
""" Basic error handler
@@ -373,9 +374,9 @@ def reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
373
374
argsAPI = {'devKey' : self .devKey ,
374
375
'testcaseid' : testcaseid ,
375
376
'testplanid' : testplanid ,
376
- 'buildname' :buildname ,
377
377
'status' : status ,
378
- 'notes' : notes
378
+ 'buildname' : buildname ,
379
+ 'notes' : str (notes )
379
380
}
380
381
return self .server .tl .reportTCResult (argsAPI )
381
382
@@ -588,18 +589,20 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
588
589
raise TestLinkErrors ("(getTestCaseIDByName) - Internal server error. Return value is not expected one!" )
589
590
590
591
591
- def reportResult (self , testResult , testCaseName , testSuiteName , testNotes , ** kwargs ):
592
+ def reportResult (self , testResult , testCaseName , testSuiteName , testNotes = "" , ** kwargs ):
592
593
"""
593
594
Report results for test case
594
595
Arguments are:
595
596
- testResult: "p" for passed, "b" for blocked, "f" for failed
596
597
- testCaseName: the test case name to report
597
598
- 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
598
600
- an anonymous dictionnary with followings keys:
599
601
- testProjectName: the project to fill
600
602
- testPlanName: the active test plan
601
603
- buildName: the active build.
602
604
Raise a TestLinkErrors error with the error message in case of trouble
605
+ Return the execution id needs to attach files to test execution
603
606
"""
604
607
605
608
# Check parameters
@@ -613,29 +616,51 @@ def reportResult(self, testResult, testCaseName, testSuiteName, testNotes, **kwa
613
616
# Check if project is active
614
617
if project ['active' ] != '1' :
615
618
raise TestLinkErrors ("(reportResult) - Test project %s is not active" % kwargs ["testProjectName" ])
616
- # Memorize project id
617
- projectId = project ['id' ]
618
619
619
620
# Check test plan name
620
621
plan = self .getTestPlanByName (kwargs ["testProjectName" ], kwargs ["testPlanName" ])
621
622
622
623
# 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' :
624
625
raise TestLinkErrors ("(reportResult) - Test plan %s is not active or not open" % kwargs ["testPlanName" ])
626
+ # Memorise test plan id
627
+ planId = plan ['id' ]
625
628
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" ])
626
638
627
639
# Check results parameters
628
- if testResults not in "pbf" :
640
+ if testResult not in "pbf" :
629
641
raise TestLinkErrors ("(reportResult) - Test result must be 'p', 'f' or 'b'" )
630
642
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' ]
634
659
635
660
def getTestProjectByName (self , testProjectName ):
636
661
"""
637
662
Return project
638
- A TestLinkError is raised in case of error
663
+ A TestLinkErrors is raised in case of error
639
664
"""
640
665
results = super (TestLink , self ).getTestProjectByName (testProjectName )
641
666
if results [0 ].has_key ("message" ):
@@ -650,6 +675,28 @@ def getTestPlanByName(self, testProjectName, testPlanName):
650
675
"""
651
676
results = super (TestLink , self ).getTestPlanByName (testProjectName , testPlanName )
652
677
if results [0 ].has_key ("message" ):
653
- raise TestLinkErrors (results [0 ]. ["message" ])
678
+ raise TestLinkErrors (results [0 ]["message" ])
654
679
655
680
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