Skip to content

Commit eb9b8cc

Browse files
committed
reportResults is OK, except 'notes' that reporting
1 parent e17d4e8 commit eb9b8cc

File tree

2 files changed

+79
-15
lines changed

2 files changed

+79
-15
lines changed

test.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,23 @@ def test_getTestProjectByName(self):
4242
assert_raises(TestLinkErrors, self.client.getTestProjectByName, "Unknown project")
4343

4444
def test_getTestPlanByName(self):
45-
#print self.client.getTestPlanByName("Test 2", "Full")
46-
#print self.client.getTestPlanByName("Test 2", "Name Error")
47-
#assert_equal(True, False)
45+
plan_ok = self.client.getTestPlanByName("Test 2", "Full")
46+
47+
# Assume that plan id is 33
48+
assert_equal(plan_ok['id'], '33')
49+
50+
assert_raises(TestLinkErrors, self.client.getTestPlanByName, "Test 2", "Name Error")
51+
52+
def test_getBuildByName(self):
53+
pass
54+
55+
def test_reportResult(self):
56+
dico = {'testProjectName': 'Automatique',
57+
'testPlanName': 'FullAuto',
58+
'buildName': 'V0.1'}
59+
execid = self.client.reportResult("p", "test1", "S1", "An example of note", **dico)
60+
assert_equal(type(execid), str)
61+
62+
execid = self.client.reportResult("f", "test2", "S1", **dico)
63+
assert_equal(type(execid), str)
64+

testlink.py

+59-12
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
import xmlrpclib
1313
import sys
14+
from datetime import date
1415

1516
class 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

Comments
 (0)