Skip to content

Commit e57d919

Browse files
committed
Adding new class TestCase, TestSuite and TestProject
1 parent 18c457a commit e57d919

File tree

4 files changed

+164
-50
lines changed

4 files changed

+164
-50
lines changed

test.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ def test_getTestCasesForTestPlan(self):
6666
results = self.client.getTestCasesForTestPlan("Automatique", "FullAuto")
6767
for result in results:
6868
print result
69+
#TODO
70+
# assert_equal(type(results), list)
6971

70-
assert_equal(type(results), list)
71-
72-
for elem in results:
73-
assert_equal(type(elem), dict)
72+
#for elem in results:
73+
#assert_equal(type(elem), dict)
7474

7575
def test_getTestCaseCustomFieldDesignValue(self):
7676
test_list = self.client.getTestCasesForTestPlan("Automatique", "FullAuto")
@@ -90,7 +90,17 @@ def test_getTestCaseByExtID(self):
9090
assert_raises(TestLinkErrors, self.client.getTestCaseByExtID, 'Id not known')
9191

9292
extid = 'auto-5'
93-
results = self.client.getTestCaseByExtID(extid)
94-
assert_equal(results['full_tc_external_id'], extid)
93+
tc = self.client.getTestCaseByExtID(extid)
94+
assert_equal(tc.extid, extid)
95+
96+
def test_getTestCase(self):
97+
"""getTestCase test method"""
98+
99+
tc = self.client.getTestCase(testcaseexternalid='auto-5')
100+
101+
# tc must be an TestCase object
102+
assert_equal(tc.extid, 'auto-5')
95103

104+
# Test failed Return
105+
assert_raises(TestLinkErrors, self.client.getTestCase, 'Id not known')
96106

test.pyc

4.69 KB
Binary file not shown.

testlink.py

Lines changed: 148 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,19 @@ def getProjectTestPlans(self, testprojectid):
126126
'testprojectid':str(testprojectid)}
127127
return self.server.tl.getProjectTestPlans(argsAPI)
128128

129-
def getTestCase(self, testcaseid=None, testcaseexternalid=None):
129+
def getTestCase(self, testcaseid=None, testcaseexternalid=None, version=None):
130130
""" getTestCase :
131-
Gets test case specification using external or internal id
131+
Gets test case specification using external or internal id and its verion
132+
(if version is not specified, the higher version is used)
132133
"""
133134

134135
argsAPI = {'devKey' : self.devKey}
135136
if testcaseexternalid is not None:
136137
argsAPI.update({'testcaseexternalid': str(testcaseexternalid)})
137138
elif testcaseid is not None:
138139
argsAPI.update({'testcaseid': str(testcaseid)})
140+
if version is not None:
141+
argsAPI.update({'version': str(version)})
139142

140143
return self.server.tl.getTestCase(argsAPI)
141144

@@ -558,15 +561,45 @@ def getProjectIDByName(self, projectName):
558561
return result
559562

560563
def __str__(self):
561-
message = """
562-
TestLinkAPIClient - version %s
563-
@author: Olivier Renault (admin@sqaopen.net)
564-
@author: kereval.com
565-
@author: Patrick Dassier
566-
567-
"""
564+
message = "TestLinkAPIClient - version %s"
568565
return message % self.__VERSION__
569566

567+
class TestCase(object):
568+
"""Test case object"""
569+
570+
def __init__(self):
571+
self.id = ''
572+
self.extid = ''
573+
self.version = ''
574+
self.is_open = False
575+
self.is_active = False
576+
self.name = ''
577+
self.summary = ''
578+
self.preconditions = ''
579+
# Must be 'auto' or 'manual'
580+
self.execution_type = ''
581+
self.testsuite = TestSuite()
582+
583+
class TestSuite(object):
584+
"""TestSuite object"""
585+
def __init__(self):
586+
self.id = ''
587+
self.details = ''
588+
self.name = ''
589+
self.node_order = ''
590+
self.node_type_id = ''
591+
self.parent = None
592+
self.is_root = False
593+
self.project = None
594+
595+
class TestProject(object):
596+
"""TestProject object"""
597+
def __init__(self):
598+
self.id = ''
599+
self.is_active = False
600+
self.is_public = False
601+
self.name = ''
602+
570603
class TestLink(TestLinkAPIClient):
571604
"""
572605
TestLink API library
@@ -580,6 +613,96 @@ def __init__(self, server_url, key):
580613
"""
581614
super(TestLink, self).__init__(server_url, key)
582615

616+
def getTestProjectByID(self, testprojectid):
617+
"""
618+
Return a project according to its id
619+
A TestLinkErrors is raised if id is not found
620+
"""
621+
# First get all projects
622+
projects = self.getProjects()
623+
624+
for p in projects:
625+
if p['id'] == testprojectid:
626+
prj = TestProject()
627+
prj.id = p['id']
628+
prj.is_active = p['active'] == '1'
629+
prj.is_public = p['is_public'] == '1'
630+
prj.name = p['name']
631+
return prj
632+
# No project found, raise an error
633+
raise TestLinkErrors("(getProjectByID) - Project with id %s is not found" % testprojectid)
634+
635+
636+
def getTestSuiteByID(self, testsuiteid):
637+
"""docstring for getTestSuiteByID"""
638+
result = super(TestLink, self).getTestSuiteByID(testsuiteid)
639+
640+
# Check error
641+
if type(result) == list and 'message' in result[0]:
642+
raise TestLinkErrors(result[0]['message'])
643+
644+
ts = TestSuite()
645+
ts.id = result['id']
646+
ts.details = result['details']
647+
ts.name = result['name']
648+
ts.node_order = result['node_order']
649+
ts.node_type_id = result['node_type_id']
650+
651+
# Is parent_id an id of a test suite ?
652+
try:
653+
ts_parent = self.getTestSuiteByID(result['parent_id'])
654+
except TestLinkErrors:
655+
# Parent is not a test suite, so it is a project
656+
ts.project = self.getTestProjectByID(result['parent_id'])
657+
ts.parent = None
658+
ts.is_root = True
659+
else:
660+
# Parent is a test suite
661+
# register it
662+
ts.parent = ts_parent
663+
ts.is_root = False
664+
665+
# Also register the project
666+
# find it in parent object
667+
ts.project = ts.parent.project
668+
669+
return ts
670+
671+
def getTestCase(self, testcaseid=None, testcaseexternalid=None, version=None):
672+
"""
673+
Return the TestCase object according to parameters
674+
"""
675+
# Check parameters
676+
if testcaseid is None and testcaseexternalid is None:
677+
raise TestLinkErrors("(getTestCase) - You must specified 'testcaseid' or 'testcaseexternalid'")
678+
679+
result = super(TestLink, self).getTestCase(testcaseid, testcaseexternalid, version)
680+
681+
# Check error
682+
if 'message' in result[0]:
683+
raise TestLinkErrors(result[0]['message'])
684+
685+
686+
# Create TestCase object
687+
tc = TestCase()
688+
tc.id = result[0]['testcase_id']
689+
tc.extid = result[0]['full_tc_external_id']
690+
tc.version = result[0]['version']
691+
tc.is_active = result[0]['active'] == '1'
692+
tc.is_open = result[0]['is_open'] == '1'
693+
tc.name = result[0]['name']
694+
tc.summary = result[0]['summary']
695+
tc.preconditions = result[0]['preconditions']
696+
if result[0]['execution_type'] == '2':
697+
#Automatic test
698+
tc.execution_type = 'auto'
699+
else:
700+
# Manual testProjectName
701+
tc.execution_type = 'manual'
702+
tc.testsuite = self.getTestSuiteByID(result[0]['testsuite_id'])
703+
704+
return tc
705+
583706
def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
584707
"""
585708
Find a test case by its name, by its suite and its project
@@ -600,20 +723,6 @@ def getTestCaseIDByName(self, testCaseName, testSuiteName, testProjectName):
600723
def getTestCasesForTestPlan(self, testProjectName, testPlanName):
601724
"""
602725
Return a list of tests case object of testProjectName project, for the selected test plan
603-
The return list is a list of the following dict:
604-
{'tcase_id': test case id
605-
'platform_id': ?
606-
'tcversion_id': another internal id
607-
'tc_id': same as tcase_di
608-
'execution_type': ??
609-
'feature_id': ??
610-
'version': test case version
611-
'full_external_id': the external id (as shown in the testlink interface: <name>-<unique number>
612-
'external_id': just the nubmer of the full_external_id
613-
'plateform_name': ??
614-
'execution_order': test case priority
615-
'exec_status': 'p' for pass, 'f' for failed, 'b' for blocked', 'n' for not run
616-
}
617726
"""
618727

619728
# Get test plan ID
@@ -624,37 +733,36 @@ def getTestCasesForTestPlan(self, testProjectName, testPlanName):
624733

625734
ret_value = []
626735
for k in results.keys():
627-
ret_value.append(results[k][0])
736+
# Get test case object associated of return test case id
737+
# and append it to test case list
738+
ret_value.append(self.getTestCase(testcaseid=k))
628739

629740
return ret_value
630741

631-
def getTestCaseCustomFieldDesignValue(self, customFieldName, testProjectName, testCaseObject):
742+
def getTestCaseCustomFieldDesignValue(self, customFieldName, testCaseObject):
632743
"""
633744
Return custom fields value for the specified test case object
634-
Test case object is an object return by 'getTestCaseByExtID' method
635-
testProjectName is the name of test project (test case must be a test case of
636-
the given test project name
637-
Nota: test case version used is the last test case version
745+
Test case object is an object return by 'getTestCase' method
638746
A TestLinkErrors is raised is case of problem
639747
"""
640748

641-
extid = testCaseObject['full_external_id']
642-
version = testCaseObject['version']
643-
projectid = self.getProjectIDByName(testProjectName)
749+
extid = testCaseObject.extid
750+
version = testCaseObject.version
751+
projectid = testCaseObject.testsuite.project.id
644752

645753
results = super(TestLink, self).getTestCaseCustomFieldDesignValue(extid, version, projectid, customFieldName)
646754

647755
return results
648756

649-
def getProjectIDByName(self, testProjectName):
650-
""" Return project id
757+
def getTestProjectByName(self, testProjectName):
758+
""" Return project object correcponding to the testProjectName name
651759
or raise a TestLinkErrors if project name is not found
652760
"""
653-
results = super(TestLink, self).getProjectIDByName(testProjectName)
654-
if results == -1:
655-
raise TestLinkErrors("(getProjectIDByName) - Project %s is not found" % testProjectName)
761+
prj_id = self.getProjectIDByName(testProjectName)
762+
if prj_id == -1:
763+
raise TestLinkErrors("(getProjectByName) - Project %s is not found" % testProjectName)
656764
else:
657-
return results
765+
return self.getTestProjectByID(prj_id)
658766

659767
def reportResult(self, testResult, testCaseName, testSuiteName, testNotes="", **kwargs):
660768
"""
@@ -768,12 +876,8 @@ def getBuildByName(self, testProjectName, testPlanName, buildName):
768876

769877
def getTestCaseByExtID(self, testCaseExternalID):
770878
"""Return test case by its external ID
771-
Raise an error if external ID is not found"""
772-
results = self.getTestCase(testcaseexternalid=testCaseExternalID)
773-
774-
if 'message' in results[0]:
775-
raise TestLinkErrors(results[0]['message'])
776-
return results[0]
879+
Error are managed by getTestCase method"""
880+
return self.getTestCase(testcaseexternalid=testCaseExternalID)
777881

778882
class TestEngine(object):
779883
"""This class must be derived to implement an automatic test engine"""

testlink.pyc

37 KB
Binary file not shown.

0 commit comments

Comments
 (0)