Skip to content

Commit e17d4e8

Browse files
committed
Add getTestProjectByName
1 parent 9713fcc commit e17d4e8

File tree

2 files changed

+81
-33
lines changed

2 files changed

+81
-33
lines changed

test.py

+13-8
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,16 @@ def test_getTestCaseIDByName(self):
3232
# 31 is test case id
3333
assert_equal(val, '31' )
3434

35-
try:
36-
val = self.client.getTestCaseIDByName("Initialisation", "Séquence 1", "Test 2")
37-
except TestLinkErrors, e:
38-
assert_equal(str(e), "(getTestCaseIDByName) - Several case test found. Suite name must not be duplicate for the same project")
39-
else:
40-
print "An error message is expected !"
41-
assert_equal(False, True)
42-
35+
# Check if an error is raised in case of bad parameters
36+
assert_raises(TestLinkErrors, self.client.getTestCaseIDByName, "Initialisation", "Séquence 1", "Test 2")
37+
38+
def test_getTestProjectByName(self):
39+
project = self.client.getTestProjectByName("Test 2")
40+
assert_equals(type(project), dict)
41+
# Check if an error is raised in case of bad parameters
42+
assert_raises(TestLinkErrors, self.client.getTestProjectByName, "Unknown project")
43+
44+
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)

testlink.py

+68-25
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,6 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName=None, testProjectName=
177177
else:
178178
return ret_srv
179179

180-
181-
182-
183180
def getTestCasesForTestPlan(self, *args):
184181
""" getTestCasesForTestPlan :
185182
List test cases linked to a test plan
@@ -362,7 +359,7 @@ def createTestCase(self, *args):
362359
self.stepsList = []
363360
return ret
364361

365-
def __reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
362+
def reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
366363
"""
367364
Report execution result
368365
testcaseid: internal testlink id of the test case
@@ -382,24 +379,6 @@ def __reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
382379
}
383380
return self.server.tl.reportTCResult(argsAPI)
384381

385-
def reportResult(self, testCaseName, testSuiteName, testProjectName):
386-
pass
387-
388-
def setReportCtx(self, testProjectName, testPlanName, buildName):
389-
"""
390-
Set project name test plan name and build name for reportResult function
391-
"""
392-
project = getTestProjectByName(testProjectName)
393-
if project[0].has_key("message"):
394-
sys.exit(project[0]["message"])
395-
396-
# Check if project is active
397-
if project[0]['active'] != '1':
398-
sys.exit("(getTestProjectByName) - Test project (name:%s) is not active" % testProjectName)
399-
400-
# Store project id
401-
self.projectId = project[0]['id']
402-
#TODO: à finir
403382

404383

405384
def uploadExecutionAttachment(self,attachmentfile,executionid,title,description):
@@ -589,8 +568,7 @@ def __init__(self, server_url, key):
589568
"""
590569
Class initialisation
591570
"""
592-
593-
super(testlink, self).__init__(server_url, key)
571+
super(TestLink, self).__init__(server_url, key)
594572

595573
def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
596574
"""
@@ -599,7 +577,7 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
599577
Return test case id if success
600578
or raise TestLinkErrors exception with error message in case of error
601579
"""
602-
results = super(testlink, self).getTestCaseIDByName(testCaseName, testSuiteName, testProjectName)
580+
results = super(TestLink, self).getTestCaseIDByName(testCaseName, testSuiteName, testProjectName)
603581
if results[0].has_key("message"):
604582
raise TestLinkErrors(results[0]["message"])
605583
elif len(results) > 1:
@@ -610,3 +588,68 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
610588
raise TestLinkErrors("(getTestCaseIDByName) - Internal server error. Return value is not expected one!")
611589

612590

591+
def reportResult(self, testResult, testCaseName, testSuiteName, testNotes, **kwargs):
592+
"""
593+
Report results for test case
594+
Arguments are:
595+
- testResult: "p" for passed, "b" for blocked, "f" for failed
596+
- testCaseName: the test case name to report
597+
- testSuiteName: the test suite name that support the test case
598+
- an anonymous dictionnary with followings keys:
599+
- testProjectName: the project to fill
600+
- testPlanName: the active test plan
601+
- buildName: the active build.
602+
Raise a TestLinkErrors error with the error message in case of trouble
603+
"""
604+
605+
# Check parameters
606+
for data in ["testProjectName", "testPlanName", "buildName"]:
607+
if not kwargs.has_key(data):
608+
raise TestLinkErrors("(reportResult) - Missing key %s in anonymous dictionnary" % data)
609+
610+
# Get project id
611+
project = self.getTestProjectByName(kwargs["testProjectName"])
612+
613+
# Check if project is active
614+
if project['active'] != '1':
615+
raise TestLinkErrors("(reportResult) - Test project %s is not active" % kwargs["testProjectName"])
616+
# Memorize project id
617+
projectId = project['id']
618+
619+
# Check test plan name
620+
plan = self.getTestPlanByName(kwargs["testProjectName"], kwargs["testPlanName"])
621+
622+
# Check is test plan is open and active
623+
if results[0]['is_open'] != '1' or results[0]['active'] != '1':
624+
raise TestLinkErrors("(reportResult) - Test plan %s is not active or not open" % kwargs["testPlanName"])
625+
626+
627+
# Check results parameters
628+
if testResults not in "pbf":
629+
raise TestLinkErrors("(reportResult) - Test result must be 'p', 'f' or 'b'")
630+
631+
632+
results = self.reportTCResult(testCaseName, testSuiteName, testProjectName)
633+
#TODO: à terminer
634+
635+
def getTestProjectByName(self, testProjectName):
636+
"""
637+
Return project
638+
A TestLinkError is raised in case of error
639+
"""
640+
results = super(TestLink, self).getTestProjectByName(testProjectName)
641+
if results[0].has_key("message"):
642+
raise TestLinkErrors(results[0]["message"])
643+
644+
return results[0]
645+
646+
def getTestPlanByName(self, testProjectName, testPlanName):
647+
"""
648+
Return test plan
649+
A TestLinkErrors is raised in case of error
650+
"""
651+
results = super(TestLink, self).getTestPlanByName(testProjectName, testPlanName)
652+
if results[0].has_key("message"):
653+
raise TestLinkErrors(results[0].["message"])
654+
655+
return results[0]

0 commit comments

Comments
 (0)