Skip to content

Commit 447beb7

Browse files
author
Brian Williams
committed
Add getTestCaseByVersion
Several API endpoints require a version and getting the latest/specifc version with `getTestCaseByVersion` can be useful.
1 parent a514397 commit 447beb7

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

Diff for: README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ how existing code can be adapted
9292
TestLink-API-Python-client developers
9393
-------------------------------------
9494
* `James Stock`_, `Olivier Renault`_, `lczub`_, `manojklm`_ (PY3)
95-
* `g4l4drim`_, `pade`_, `anton-matosov`_, `citizen-stig`_, `charz`_, `Maberi`_
95+
* `g4l4drim`_, `pade`_, `anton-matosov`_, `citizen-stig`_, `charz`_, `Maberi`_, `Brian-Williams`_
9696
* anyone forgotten?
9797

9898
.. _Apache License 2.0: http://www.apache.org/licenses/LICENSE-2.0

Diff for: src/testlink/testlinkapi.py

+18-2
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,23 @@ def copyTCnewTestCase(self, origTestCaseId, origVersion=None, **changedAttribute
212212
return self._copyTC(origTestCaseId, changedAttributes, origVersion,
213213
duplicateaction = 'generate_new')
214214

215-
215+
def getTestCaseByVersion(self, testCaseID, version=None):
216+
"""
217+
Gets testcase information based on the version.
218+
219+
:param testCaseID: test case to search for
220+
:param version: version to search for defaults to None. None searches for latest
221+
:return: test case info dictionary
222+
"""
223+
testcases = self.getTestCase(testCaseID, version=version)
224+
if version is None:
225+
return testcases[0]
226+
for testcase in testcases:
227+
if str(testcase['version']) == str(version):
228+
return testcase
229+
else:
230+
raise RuntimeError("Testcase {} doesn't have version {}.".format(testCaseID, version))
231+
216232
def _copyTC(self, origTestCaseId, changedArgs, origVersion=None, **options):
217233
""" creates a copy of test case with id ORIGTESTCASEID
218234
@@ -237,7 +253,7 @@ def _copyTC(self, origTestCaseId, changedArgs, origVersion=None, **options):
237253
"""
238254

239255
# get orig test case content
240-
origArgItems = self.getTestCase(origTestCaseId, version=origVersion)[0]
256+
origArgItems = self.getTestCaseByVersion(origTestCaseId, version=origVersion)
241257
# get orig test case project id
242258
origArgItems['testprojectid'] = self.getProjectIDByNode(origTestCaseId)
243259

0 commit comments

Comments
 (0)