Skip to content

Commit 46d65c0

Browse files
author
Luiko Czub
committed
server call methods shifted to generic API lczub#7
createBuild, reportTCResult
1 parent 518ebf4 commit 46d65c0

File tree

5 files changed

+114
-56
lines changed

5 files changed

+114
-56
lines changed

example/TestLinkExample.py

+21
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585
NEWTESTSUITE_AA="AA - Second Level"
8686
NEWTESTCASE_AA="TESTCASE_AA"
8787
NEWTESTCASE_B="TESTCASE_B"
88+
NEWBUILD="Build v0.4.5"
8889

8990

9091
if myTestLink.checkDevKey() != True:
@@ -237,6 +238,26 @@
237238
'testcaseexternalid' : tc_b_full_ext_id, 'version' : 1})
238239
print response
239240

241+
# -- Create Build
242+
newBuild = myTestLink.createBuild(newTestPlanID, NEWBUILD, 'Notes for the Build')
243+
print newBuild
244+
isOk = newBuild[0]['message']
245+
if isOk=="Success!":
246+
newBuildID = newBuild[0]['id']
247+
print "New Build '%s' - id: %s" % (NEWBUILD, newBuildID)
248+
else:
249+
print "Error creating the Build '%s': %s " % (NEWBUILD, isOk)
250+
sys.exit(-1)
251+
252+
# report Test Case Results
253+
# TC_AA failed
254+
newResult = myTestLink.reportTCResult(newTestPlanID, newTestCaseID_AA, NEWBUILD,
255+
'f', '')
256+
print newResult
257+
# TC_B passed, explicit build and some notes , TC identified with internal id
258+
newResult = myTestLink.reportTCResult(newTestPlanID, newTestCaseID_B, NEWBUILD,
259+
'p', 'first try')
260+
print newResult
240261

241262
print ""
242263
print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),)

example/TestLinkExampleGenericApi.py

+25-1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@
7575
NEWTESTSUITE_AA="AA - Second Level"
7676
NEWTESTCASE_AA="TESTCASE_AA"
7777
NEWTESTCASE_B="TESTCASE_B"
78+
NEWBUILD="Build v0.4.5"
7879

7980
id_cache={}
8081

@@ -105,7 +106,7 @@
105106

106107
# Creates the test plan
107108
newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT,
108-
notes='New TestPlan created with the API',active=1, public=1)
109+
notes='New TestPlan created with the Generic API',active=1, public=1)
109110
isOk = newTestPlan[0]['message']
110111
if isOk=="Success!":
111112
id_cache[NEWTESTPLAN] = newTestPlan[0]['id']
@@ -217,6 +218,29 @@
217218
'testcaseexternalid' : tc_b_full_ext_id, 'version' : 1})
218219
print response
219220

221+
# -- Create Build
222+
newBuild = myTestLink.createBuild(id_cache[NEWTESTPLAN], NEWBUILD,
223+
buildnotes='Notes for the Build')
224+
print newBuild
225+
isOk = newBuild[0]['message']
226+
if isOk=="Success!":
227+
id_cache[NEWBUILD] = newBuild[0]['id']
228+
print "New Build '%s' - id: %s" % (NEWBUILD, id_cache[NEWBUILD])
229+
else:
230+
print "Error creating the Build '%s': %s " % (NEWBUILD, isOk)
231+
sys.exit(-1)
232+
233+
# report Test Case Results
234+
# TC_AA failed, build should be guessed, TC identified with external id
235+
newResult = myTestLink.reportTCResult(id_cache[NEWTESTPLAN], 'f', guess=True,
236+
testcaseexternalid=tc_aa_full_ext_id)
237+
print newResult
238+
# TC_B passed, explicit build and some notes , TC identified with internal id
239+
newResult = myTestLink.reportTCResult(id_cache[NEWTESTPLAN], 'p',
240+
buildid=id_cache[NEWBUILD], testcaseid=id_cache[NEWTESTCASE_B],
241+
notes="first try")
242+
print newResult
243+
220244
print ""
221245
print "Number of Projects in TestLink: %i " % len(myTestLink.getProjects())
222246
print ""

src/testlink/testlinkapi.py

+33-29
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ def _changePositionalArgConfig(self):
4343
'testprojectid', 'authorlogin', 'summary'] #, 'steps']
4444
# getTestCase
4545
pos_arg_config['getTestCase'] = ['testcaseid']
46-
46+
# createVuild
47+
pos_arg_config['createBuild'] = ['testplanid', 'buildname', 'buildnotes']
48+
# reportTCResult
49+
pos_arg_config['reportTCResult'] = ['testcaseid', 'testplanid',
50+
'buildname', 'status', 'notes']
4751
#
4852
# BUILT-IN API CALLS
4953
#
@@ -304,15 +308,15 @@ def getTotalsForTestPlan(self, testplanid):
304308
# argsAPI[paramlist[0]] = paramlist[1]
305309
# return self._callServer('createTestProject', argsAPI)
306310

307-
def createBuild(self, testplanid, buildname, buildnotes):
308-
""" createBuild :
309-
Creates a new build for a specific test plan
310-
"""
311-
argsAPI = {'devKey' : self.devKey,
312-
'testplanid' : str(testplanid),
313-
'buildname' : str(buildname),
314-
'buildnotes' : str(buildnotes)}
315-
return self._callServer('createBuild', argsAPI)
311+
# def createBuild(self, testplanid, buildname, buildnotes):
312+
# """ createBuild :
313+
# Creates a new build for a specific test plan
314+
# """
315+
# argsAPI = {'devKey' : self.devKey,
316+
# 'testplanid' : str(testplanid),
317+
# 'buildname' : str(buildname),
318+
# 'buildnotes' : str(buildnotes)}
319+
# return self._callServer('createBuild', argsAPI)
316320

317321
# def createTestPlan(self, *args):
318322
# """ createTestPlan :
@@ -391,25 +395,25 @@ def createTestCase(self, *argsPositional, **argsOptional):
391395
# self.stepsList = []
392396
# return ret
393397

394-
def reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
395-
"""
396-
Report execution result
397-
testcaseid: internal testlink id of the test case
398-
testplanid: testplan associated with the test case
399-
buildname: build name of the test case
400-
status: test verdict ('p': pass,'f': fail,'b': blocked)
401-
402-
Return : [{'status': True, 'operation': 'reportTCResult', 'message': 'Success!', 'overwrite': False, 'id': '37'}]
403-
id correspond to the executionID needed to attach files to a test execution
404-
"""
405-
argsAPI = {'devKey' : self.devKey,
406-
'testcaseid' : testcaseid,
407-
'testplanid' : testplanid,
408-
'status': status,
409-
'buildname': buildname,
410-
'notes': str(notes)
411-
}
412-
return self._callServer('reportTCResult', argsAPI)
398+
# def reportTCResult(self, testcaseid, testplanid, buildname, status, notes ):
399+
# """
400+
# Report execution result
401+
# testcaseid: internal testlink id of the test case
402+
# testplanid: testplan associated with the test case
403+
# buildname: build name of the test case
404+
# status: test verdict ('p': pass,'f': fail,'b': blocked)
405+
#
406+
# Return : [{'status': True, 'operation': 'reportTCResult', 'message': 'Success!', 'overwrite': False, 'id': '37'}]
407+
# id correspond to the executionID needed to attach files to a test execution
408+
# """
409+
# argsAPI = {'devKey' : self.devKey,
410+
# 'testcaseid' : testcaseid,
411+
# 'testplanid' : testplanid,
412+
# 'status': status,
413+
# 'buildname': buildname,
414+
# 'notes': str(notes)
415+
# }
416+
# return self._callServer('reportTCResult', argsAPI)
413417

414418

415419

src/testlink/testlinkapigeneric.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@
3131
# subclasses could override this definition, if their (python) method should
3232
# work with different positional arguments
3333
positionalArgNamesDefault = {
34+
'createBuild' : ['testplanid', 'buildname'],
3435
'createTestCase' : ['testcasename', 'testsuiteid', 'testprojectid',
3536
'authorlogin', 'summary', 'steps'],
3637
'createTestPlan' : ['testplanname', 'testprojectname'],
3738
'createTestProject' : ['testprojectname', 'testcaseprefix'],
3839
'createTestSuite' : ['testprojectid', 'testsuitename', 'details'],
3940
'doesUserExist' : ['user'],
40-
'repeat' : ['str']
41+
'repeat' : ['str'],
42+
'reportTCResult' : ['testplanid', 'status']
4143
}
4244

4345
# decorators for generic api calls
@@ -106,18 +108,15 @@ def about(self):
106108
positional args: ---
107109
optional args : --- """
108110

109-
# * Creates a new build for a specific test plan
110-
# *
111-
# * @param struct $args
112-
# * @param string $args["devKey"]
113-
# * @param int $args["testplanid"]
114-
# * @param string $args["buildname"];
115-
# * @param string $args["buildnotes"];
116-
# * @return mixed $resultInfo
117-
# public function createBuild($args)
118-
119111
@decoApiCallAddDevKey
120112
@decoApiCallWithArgs
113+
def createBuild(self):
114+
""" createBuild: Creates a new build for a specific test plan
115+
positional args: testplanid, buildname
116+
optional args : buildnotes """
117+
118+
@decoApiCallAddDevKey
119+
@decoApiCallWithArgs
121120
def getProjects(self):
122121
""" getProjects: Gets a list of all projects
123122
positional args: ---
@@ -277,6 +276,20 @@ def createTestCase(self):
277276
# */
278277
# public function reportTCResult($args)
279278

279+
@decoApiCallAddDevKey
280+
@decoApiCallWithArgs
281+
def reportTCResult(self):
282+
""" reportTCResult : Reports a result for a single test case
283+
positional args: testplanid, status
284+
optional args (variations): testcaseid - testcaseexternalid
285+
buildid - buildname
286+
platformid - platformname
287+
optional args : notes, guess, bugid, customfields, overwrite
288+
289+
customfields : dictionary with customfields names + values
290+
VERY IMPORTANT: value must be formatted in the way it's written to db
291+
"""
292+
280293
# /**
281294
# * turn on/off testMode
282295
# *
@@ -1128,7 +1141,7 @@ def _convertPostionalArgs(self, methodName, valueList):
11281141
if length_NameList != length_ValueList:
11291142
new_msg = '%s - mismatching number of positional args %i vs %i' %\
11301143
(methodName, length_NameList, length_ValueList)
1131-
new_msg = '%s\n expected args: %s' % (new_msg, ' - '.join(nameList))
1144+
new_msg = '%s\n expected args: %s' % (new_msg, ', '.join(nameList))
11321145
raise testlinkerrors.TLArgError(new_msg)
11331146
return {nameList[x] : valueList[x] for x in range(len(nameList)) }
11341147

test/utest/testlinkapigeneric_online_test.py

+10-14
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ def test_getTestCase_unknownExternalID(self):
138138
# FAILURE in 1.9.3 API message: replacement does not work
139139
# The Test Case ID (testcaseid: %s) provided does not exist!
140140
#self.assertIn('4711', response[0]['message'])
141-
print response
142141
self.assertEqual(5040, response[0]['code'])
143142

144143
# def test_getTestCaseAttachments_unknownID(self):
@@ -204,19 +203,16 @@ def test_getTestCase_unknownExternalID(self):
204203
# self.assertIn('4711', response[0]['message'])
205204
# self.assertEqual(3000, response[0]['code'])
206205

207-
# def test_createBuild_unknownID(self):
208-
# response = self.client.createBuild(4711, 'Build 4712', 'note 4713')
209-
# self.assertIn('4711', response[0]['message'])
210-
# self.assertEqual(3000, response[0]['code'])
211-
#
212-
# def test_reportTCResult_unknownID(self):
213-
# response = self.client.reportTCResult(4711, 4712, 'build 4713', 'p',
214-
# 'note 4714')
215-
# # FAILURE in 1.9.3 API message: replacement does not work
216-
# # The Test Case ID (testcaseid: %s) provided does not exist!
217-
# #self.assertIn('4711', response[0]['message'])
218-
# self.assertEqual(5000, response[0]['code'])
219-
#
206+
def test_createBuild_unknownID(self):
207+
response = self.client.createBuild(4711, 'Build 4712', buildnotes='note 4713')
208+
self.assertIn('4711', response[0]['message'])
209+
self.assertEqual(3000, response[0]['code'])
210+
211+
def test_reportTCResult_unknownID(self):
212+
response = self.client.reportTCResult(4712, 'p', testcaseid=4711, buildname='build 4713', notes='note 4714' )
213+
#response = self.client.reportTCResult(538, 'p', testcaseexternalid='GPROAPI-2', guess=True)
214+
self.assertEqual(5000, response[0]['code'])
215+
220216
# # def test_uploadExecutionAttachment_unknownID(self):
221217
# # response = self.client.uploadExecutionAttachment('file 4711', 4712,
222218
# # 'title 4713', 'descr. 4714')

0 commit comments

Comments
 (0)