Skip to content

Commit 572c2d1

Browse files
author
Luiko Czub
committed
api methods for platforms #10
createPlatform, getProjectPlatforms addPlatformToTestPlan,removePlatformFromTestPlan
1 parent 8c6140a commit 572c2d1

10 files changed

+166
-53
lines changed

Diff for: example/TestLinkExample.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -395,10 +395,19 @@
395395

396396

397397
print ""
398-
print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),)
398+
print "Number of Projects in TestLink: %s " % myTestLink.countProjects()
399+
print "Number of Platforms (in TestPlans): %s " % myTestLink.countPlatforms()
400+
print "Number of Builds : %s " % myTestLink.countBuilds()
401+
print "Number of TestPlans : %s " % myTestLink.countTestPlans()
402+
print "Number of TestSuites : %s " % myTestLink.countTestSuites()
403+
print "Number of TestCases (in TestSuites): %s " % myTestLink.countTestCasesTS()
404+
print "Number of TestCases (in TestPlans) : %s " % myTestLink.countTestCasesTP()
399405
print ""
400406
myTestLink.listProjects()
401407

408+
print
409+
print ""
410+
myTestLink.listProjects()
402411

403412

404413

Diff for: example/TestLinkExampleGenericApi.py

+68-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
Shows how to use the TestLinkAPIGeneric.
2424
- does equal things as Example TestLinkAPI in TestLinkExample.py
25+
- exception - this test project uses platforms
2526
2627
=> Counts and lists the Projects
2728
=> Create a new Project with the following structure:
@@ -72,7 +73,10 @@
7273

7374
NEWPROJECT="PROJECT_API_GENERIC-%i" % projNr
7475
NEWPREFIX="GPROAPI%i" % projNr
75-
NEWTESTPLAN="TestPlan_API_GENERIC"
76+
NEWTESTPLAN="TestPlan_API_GENERIC %i" % projNr
77+
NEWPLATFORM_A='Big Bird %i' % projNr
78+
NEWPLATFORM_B='Small Bird'
79+
NEWPLATFORM_C='Ugly Bird'
7680
NEWTESTSUITE_A="A - First Level"
7781
NEWTESTSUITE_B="B - First Level"
7882
NEWTESTSUITE_AA="AA - Second Level"
@@ -123,6 +127,39 @@
123127
newTestPlanID = newTestPlan[0]['id']
124128
print "New Test Plan '%s' - id: %s" % (NEWTESTPLAN,newTestPlanID)
125129

130+
# Create platform 'Big Bird x'
131+
newPlatForm = myTestLink.createPlatform(NEWPROJECT, NEWPLATFORM_A,
132+
notes='Platform for Big Birds, unique name, only used in this project')
133+
print "createPlatform", newPlatForm
134+
newPlatFormID_A = newPlatForm['id']
135+
# Add Platform 'Big Bird x' to platform
136+
response = myTestLink.addPlatformToTestPlan(newTestPlanID, NEWPLATFORM_A)
137+
print "addPlatformToTestPlan", response
138+
139+
# Create platform 'Small Bird'
140+
newPlatForm = myTestLink.createPlatform(NEWPROJECT, NEWPLATFORM_B,
141+
notes='Platform for Small Birds, name used in all example projects')
142+
print "createPlatform", newPlatForm
143+
newPlatFormID_B = newPlatForm['id']
144+
# Add Platform 'Small Bird' to platform
145+
response = myTestLink.addPlatformToTestPlan(newTestPlanID, NEWPLATFORM_B)
146+
print "addPlatformToTestPlan", response
147+
148+
# Create platform 'Ugly Bird'
149+
newPlatForm = myTestLink.createPlatform(NEWPROJECT, NEWPLATFORM_C,
150+
notes='Platform for Ugly Birds, will be removed from test plan')
151+
print "createPlatform", newPlatForm
152+
newPlatFormID_C = newPlatForm['id']
153+
# Add Platform 'Ugly Bird' to platform
154+
response = myTestLink.addPlatformToTestPlan(newTestPlanID, NEWPLATFORM_C)
155+
print "addPlatformToTestPlan", response
156+
157+
# looking, which platforms exists
158+
response = myTestLink.getProjectPlatforms(newProjectID)
159+
print "getProjectPlatforms", response
160+
161+
162+
126163
#Creates the test Suite A
127164
newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_A,
128165
"Details of the Test Suite A")
@@ -191,36 +228,61 @@
191228
print "New Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID_B)
192229

193230
# Add test cases to test plan - we need the full external id !
231+
# TC AA should be tested with platforms 'Big Bird'+'Small Bird'
194232
tc_aa_full_ext_id = myTestLink.getTestCase(testcaseid=newTestCaseID_AA)[0]['full_tc_external_id']
195233
response = myTestLink.callServerWithPosArgs('addTestCaseToTestPlan',
196234
devKey=myTestLink.devKey, testprojectid=newProjectID,
197235
testplanid=newTestPlanID, testcaseexternalid=tc_aa_full_ext_id,
198-
version=1)
236+
platformid=newPlatFormID_A,version=1)
199237
print "addTestCaseToTestPlan", response
238+
tc_aa_full_ext_id = myTestLink.getTestCase(testcaseid=newTestCaseID_AA)[0]['full_tc_external_id']
239+
response = myTestLink.callServerWithPosArgs('addTestCaseToTestPlan',
240+
devKey=myTestLink.devKey, testprojectid=newProjectID,
241+
testplanid=newTestPlanID, testcaseexternalid=tc_aa_full_ext_id,
242+
platformid=newPlatFormID_B,version=1)
243+
print "addTestCaseToTestPlan", response
244+
# TC B should be tested with platforms 'Small Bird'
200245
tc_b_full_ext_id = myTestLink.getTestCase(testcaseid=newTestCaseID_B)[0]['full_tc_external_id']
201246
response = myTestLink.callServerWithPosArgs('addTestCaseToTestPlan',
202247
devKey=myTestLink.devKey, testprojectid=newProjectID,
203248
testplanid=newTestPlanID, testcaseexternalid=tc_b_full_ext_id,
204-
version=1)
249+
platformid=newPlatFormID_B,version=1)
205250
print "addTestCaseToTestPlan", response
206251

252+
# Remove Platform 'Big Bird' from platform
253+
response = myTestLink.removePlatformFromTestPlan(newTestPlanID, NEWPLATFORM_C)
254+
print "removePlatformFromTestPlan", response
255+
256+
# Remove Platform 'Ugly Bird' from platform
257+
response = myTestLink.removePlatformFromTestPlan(newTestPlanID, NEWPLATFORM_C)
258+
print "removePlatformFromTestPlan", response
259+
260+
207261
# -- Create Build
208262
newBuild = myTestLink.createBuild(newTestPlanID, NEWBUILD,
209263
buildnotes='Notes for the Build')
210264
print "createBuild", newBuild
211265
newBuildID = newBuild[0]['id']
212266
print "New Build '%s' - id: %s" % (NEWBUILD, newBuildID)
213267

214-
# report Test Case Results
268+
# report Test Case Results for platform 'Big Bird'
215269
# TC_AA failed, build should be guessed, TC identified with external id
216270
newResult = myTestLink.reportTCResult(newTestPlanID, 'f', guess=True,
217-
testcaseexternalid=tc_aa_full_ext_id)
271+
testcaseexternalid=tc_aa_full_ext_id,
272+
platformname=NEWPLATFORM_A)
218273
print "reportTCResult", newResult
219274
newResultID_AA = newResult[0]['id']
275+
# report Test Case Results for platform 'Small Bird'
276+
# TC_AA passed, build should be guessed, TC identified with external id
277+
newResult = myTestLink.reportTCResult(newTestPlanID, 'p', guess=True,
278+
testcaseexternalid=tc_aa_full_ext_id,
279+
platformid=newPlatFormID_B)
280+
print "reportTCResult", newResult
281+
newResultID_AA_p = newResult[0]['id']
220282
# TC_B passed, explicit build and some notes , TC identified with internal id
221283
newResult = myTestLink.reportTCResult(newTestPlanID, 'p',
222284
buildid=newBuildID, testcaseid=newTestCaseID_B,
223-
notes="first try")
285+
platformname=NEWPLATFORM_B, notes="first try")
224286
print "reportTCResult", newResult
225287
newResultID_B = newResult[0]['id']
226288

Diff for: src/testlink/testlinkapi.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ def countTestCasesTS(self):
590590

591591
def countPlatforms(self):
592592
""" countPlatforms :
593-
Count all the Platforms
593+
Count all the Platforms in TestPlans
594594
"""
595595
projects=self.getProjects()
596596
nbPlatforms = 0

Diff for: src/testlink/testlinkapigeneric.py

+22-39
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def getTestSuiteByID(self):
375375
def getTestSuitesForTestSuite(self):
376376
""" get list of TestSuites which are DIRECT children of a given TestSuite
377377
378-
returns an empty list, if no platform is assigned """
378+
returns an empty list, if no TestSuite is assigned """
379379

380380
@decoMakerApiCallReplaceTLResponseError(3041)
381381
@decoApiCallAddDevKey
@@ -778,47 +778,30 @@ def uploadExecutionAttachment(self):
778778
# */
779779
# public function getExecCountersByBuild($args)
780780

781-
# /**
782-
# * create platform
783-
# *
784-
# * @param struct $args
785-
# * @param string $args["devKey"]
786-
# * @param int $args["testprojectname"]
787-
# * @param map $args["platformname"]
788-
# * @param map $args["notes"]
789-
# * @return mixed $resultInfo
790-
# * @internal revisions
791-
# */
792-
# public function createPlatform($args)
781+
@decoApiCallAddDevKey
782+
@decoMakerApiCallWithArgs(['testprojectname', 'platformname'],
783+
['notes'])
784+
def createPlatform(self):
785+
""" Creates a platform for test project """
793786

794-
# /**
795-
# *
796-
# */
797-
# public function getProjectPlatforms($args)
798787

799-
# /**
800-
# * addPlatformToTestPlan
801-
# *
802-
# * @param struct $args
803-
# * @param string $args["devKey"]
804-
# * @param int $args["testplanid"]
805-
# * @param map $args["platformname"]
806-
# * @return mixed $resultInfo
807-
# * @internal revisions
808-
# */
809-
# public function addPlatformToTestPlan($args)
788+
@decoMakerApiCallReplaceTLResponseError(replaceValue={})
789+
@decoApiCallAddDevKey
790+
@decoMakerApiCallWithArgs(['testprojectid'])
791+
def getProjectPlatforms(self):
792+
""" Gets a dictionary of platforms for a project
793+
794+
returns an empty dictionary, if no platform is assigned """
810795

811-
# /**
812-
# * removePlatformFromTestPlan
813-
# *
814-
# * @param struct $args
815-
# * @param string $args["devKey"]
816-
# * @param int $args["testplanid"]
817-
# * @param map $args["platformname"]
818-
# * @return mixed $resultInfo
819-
# * @internal revisions
820-
# */
821-
# public function removePlatformFromTestPlan($args)
796+
@decoApiCallAddDevKey
797+
@decoMakerApiCallWithArgs(['testplanid', 'platformname'])
798+
def addPlatformToTestPlan(self):
799+
""" Adds a platform to a test plan """
800+
801+
@decoApiCallAddDevKey
802+
@decoMakerApiCallWithArgs(['testplanid', 'platformname'])
803+
def removePlatformFromTestPlan(self):
804+
""" Removes a platform from a test plan """
822805

823806
# /**
824807
# * if everything ok returns an array on just one element with following user data

Diff for: src/testlink/testlinkdecorators.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,8 @@ def wrapperAddDevKey(self, *argsPositional, **argsOptional):
105105
return methodAPI(self, *argsPositional, **argsOptional)
106106
return wrapperAddDevKey
107107

108-
def decoMakerApiCallReplaceTLResponseError(replaceCode=None):
109-
""" creates a decorator, which replace an TLResponseError with an empty list,
108+
def decoMakerApiCallReplaceTLResponseError(replaceCode=None, replaceValue=[]):
109+
""" creates a decorator, which replace an TLResponseError with a new value
110110
111111
Default (replaceCode=None) handles the cause 'Empty Result'
112112
- ok for getProjectTestPlans, getBuildsForTestPlan, which returns just ''
@@ -115,6 +115,9 @@ def decoMakerApiCallReplaceTLResponseError(replaceCode=None):
115115
3041: Test plan (noPlatform) has no platforms linked
116116
7008: Test Project (noSuite) is empty
117117
could be handled with replaceCode=3041 / replaceCode=7008
118+
119+
Default (replaceValue=[]) new return value is an empty list
120+
- could be changed to other things like {}
118121
119122
"""
120123
# for understanding, what we are doing here please read
@@ -132,7 +135,7 @@ def wrapperReplaceTLResponseError(self, *argsPositional, **argsOptional):
132135
if tl_err.code == replaceCode:
133136
# empty result (response == '') -> code == None
134137
# special case NoPlatform -> code == 3041
135-
response = []
138+
response = replaceValue
136139
else:
137140
# seems to be another response failure - we forward it
138141
raise

Diff for: src/testlink/version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
#
1818
# ------------------------------------------------------------------------
1919

20-
VERSION = '0.4.6-DEV-15'
20+
VERSION = '0.4.6-DEV-10'

Diff for: test/utest-offline/testlinkapigeneric_offline_test.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@
5757
'name': 'TESTCASE_B'}},
5858
'listResult' : [{'parent_id': '25', 'tc_external_id': '1',
5959
'id': '26', 'tsuite_name': 'AA - Second Level',
60-
'name': 'TESTCASE_AA'}]}
60+
'name': 'TESTCASE_AA'}]},
61+
'getProjectPlatforms' : {
62+
'twoPlatforms' : {'dutch' : {'id': '1', 'name': 'dutch'},
63+
'platt' : {'id': '2', 'name': 'platt'}},
64+
'noPlatform' : {}
65+
}
6166
}
6267

6368
class DummyAPIGeneric(TestlinkAPIGeneric):
@@ -88,7 +93,7 @@ def _callServer(self, methodAPI, argsAPI=None):
8893
data = self.scenario_data[methodAPI]
8994
if methodAPI in ['doesUserExist']:
9095
response = data[argsAPI['user']]
91-
elif methodAPI in ['getProjectTestPlans',
96+
elif methodAPI in ['getProjectTestPlans', 'getProjectPlatforms',
9297
'getFirstLevelTestSuitesForTestProject']:
9398
response = data[argsAPI['testprojectid']]
9499
elif methodAPI in ['getBuildsForTestPlan', 'getTestPlanPlatforms',
@@ -241,6 +246,19 @@ def test_getProjectTestPlans_onePlan(self):
241246
self.assertEqual('21', response[0]['testproject_id'])
242247
self.assertEqual(1, len(response))
243248

249+
def test_getProjectPlatforms_noPlatform(self):
250+
self.api.loadScenario(SCENARIO_A)
251+
response = self.api.getProjectPlatforms('noPlatform')
252+
self.assertEqual({}, response)
253+
self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
254+
255+
def test_getProjectPlatforms_twoPlatforms(self):
256+
self.api.loadScenario(SCENARIO_A)
257+
response = self.api.getProjectPlatforms('twoPlatforms')
258+
self.assertEqual('1', response['dutch']['id'])
259+
self.assertEqual(2, len(response))
260+
261+
244262
def test_getBuildsForTestPlan_noBuild(self):
245263
self.api.loadScenario(SCENARIO_A)
246264
response = self.api.getBuildsForTestPlan('noBuild')

Diff for: test/utest-offline/testlinkdecoratorstest.py

+11
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,17 @@ def a_func(a_api, *argsPositional, **argsOptional):
152152
response = a_func(self.api, name='BigBird')
153153
self.assertEqual({'name' : 'BigBird'}, response)
154154

155+
def test_decoApiCallReplaceTLResponseError_replaceValue(self):
156+
" decorator test: TLResponseError should be replaced with {}"
157+
158+
@decoMakerApiCallReplaceTLResponseError(replaceValue={})
159+
def a_func(a_api, *argsPositional, **argsOptional):
160+
raise TLResponseError('DummyMethod',
161+
argsOptional, 'Empty Response! ')
162+
163+
response = a_func(self.api)
164+
self.assertEqual({}, response)
165+
155166
def test_noWrapperName_decoApiCallReplaceTLResponseError(self):
156167
" decorator test: original function name should be unchanged "
157168

Diff for: test/utest-online/testlinkapi_online_test.py

+10
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ def test_getProjects(self):
9292
def test_getProjectTestPlans_unknownID(self):
9393
with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
9494
self.client.getProjectTestPlans(4711)
95+
96+
def test_getProjectPlatforms_unknownID(self):
97+
with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
98+
self.client.getProjectPlatforms(4711)
9599

96100
def test_getTestCase_unknownID(self):
97101
with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
@@ -185,6 +189,12 @@ def test_uploadExecutionAttachment_unknownID(self):
185189
def test_getProjectIDByName_unknownID(self):
186190
response = self.client.getProjectIDByName('project 4711')
187191
self.assertEqual(-1, response)
192+
193+
def test_createPlatform_unknownID(self):
194+
with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
195+
self.client.createPlatform('Project 4711', 'Platform 4712',
196+
notes='note 4713')
197+
188198

189199

190200
if __name__ == "__main__":

Diff for: test/utest-online/testlinkapigeneric_online_test.py

+17
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ def test_getProjectTestPlans_unknownID(self):
115115
with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
116116
self.client.getProjectTestPlans(4711)
117117

118+
def test_getProjectPlatforms_unknownID(self):
119+
with self.assertRaisesRegexp(TLResponseError, '7000.*4711'):
120+
self.client.getProjectPlatforms(4711)
121+
118122
def test_getTestCase_unknownID(self):
119123
with self.assertRaisesRegexp(TLResponseError, '5000.*4711'):
120124
self.client.getTestCase(testcaseid=4711)
@@ -191,6 +195,19 @@ def test_uploadExecutionAttachment_unknownID(self):
191195
# response = self.client.getProjectIDByName('project 4711')
192196
# self.assertEqual(-1, response)
193197

198+
def test_createPlatform_unknownID(self):
199+
with self.assertRaisesRegexp(TLResponseError, '7011.*4711'):
200+
self.client.createPlatform('Project 4711', 'Platform 4712',
201+
notes='note 4713')
202+
203+
def test_addPlatformToTestPlan_unknownID(self):
204+
with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
205+
self.client.addPlatformToTestPlan(4711, 'Platform 4712')
206+
207+
def test_removePlatformFromTestPlan_unknownID(self):
208+
with self.assertRaisesRegexp(TLResponseError, '3000.*4711'):
209+
self.client.removePlatformFromTestPlan(4711, 'Platform 4712')
210+
194211

195212
if __name__ == "__main__":
196213
#import sys;sys.argv = ['', 'Test.testName']

0 commit comments

Comments
 (0)