Skip to content

Commit fc43ead

Browse files
author
Luiko Czub
committed
copyTC*() methods extended with optional argument origVersion #17
- copyTCnewVersion(origTestCaseId, origVersion=None, **changedAttributes) - copyTCnewTestCase(origTestCaseId, origVersion=None, **changedAttributes) - _copyTC(self, origTestCaseId, changedArgs, origVersion=None, **options)
1 parent 7fecff6 commit fc43ead

File tree

4 files changed

+105
-18
lines changed

4 files changed

+105
-18
lines changed

README.rst

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,22 @@ How to talk with TestLink in a python shell: ::
3131
set TESTLINK_API_PYTHON_SERVER_URL=http://[YOURSERVER]/testlink/lib/api/xmlrpc/v1/xmlrpc.php
3232
set TESTLINK_API_PYTHON_DEVKEY=[Users devKey generated by TestLink]
3333
python
34+
3435
>>> import testlink
3536
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
3637
>>> tls.countProjects()
3738
3
38-
>>> tls.getTestCase(None, testcaseexternalid='NPROAPI3-1')
39-
[{'full_tc_external_id': 'NPROAPI3-1', 'node_order': '0', 'is_open': '1', 'id': '2757', ...}]
39+
40+
>>> tc_info = tls.getTestCase(None, testcaseexternalid='NPROAPI3-2')
41+
[{'full_tc_external_id': 'NPROAPI3-2', ..., 'id': '5440', 'version': '2',
42+
'testsuite_id': '5415', 'tc_external_id': '2','testcase_id': '5425', ...}]
43+
44+
>>> tls.copyTCnewTestCase(tc_info[0]['testcase_id'], testsuiteid=newSuiteID,
45+
testcasename='a new test case name')
46+
4047
>>> print tls.whatArgs('createTestPlan')
41-
createTestPlan(<testplanname>, <testprojectname>, [note=<note>], [active=<active>], [public=<public>], [devKey=<devKey>])
48+
createTestPlan(<testplanname>, <testprojectname>, [note=<note>], [active=<active>],
49+
[public=<public>], [devKey=<devKey>])
4250
create a test plan
4351

4452
Installation

example/TestLinkExample.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,11 +478,11 @@
478478
response = myTestLink.getTestSuiteByID(newTestSuiteID_B)
479479
print "getTestSuiteByID", response
480480
response = myTestLink.getTestSuitesForTestSuite(newTestSuiteID_A)
481-
print "getTestSuitesForTestSuite", response
481+
print "getTestSuitesForTestSuite A", response
482482
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_A, True, 'full')
483-
print "getTestCasesForTestSuite", response
483+
print "getTestCasesForTestSuite A", response
484484
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False, 'only_id')
485-
print "getTestCasesForTestSuite", response
485+
print "getTestCasesForTestSuite B", response
486486

487487
# get informationen - TestCase
488488
# -- Start CHANGE v0.4.5 --
@@ -527,6 +527,10 @@
527527
response = myTestLink.copyTCnewTestCase(newTestCaseID_B,
528528
testsuiteid=newTestSuiteID_A, testcasename='%sA' % NEWTESTCASE_B)
529529
print 'copyTCnewTestCase', response
530+
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False, 'simple')
531+
print 'getTestCasesForTestSuite B', response
532+
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_A, True, 'simple')
533+
print 'getTestCasesForTestSuite A', response
530534

531535

532536
print ""

src/testlink/testlinkapi.py

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -154,34 +154,52 @@ def getProjectIDByNode(self, a_nodeid):
154154
a_project = self.getTestProjectByName(node_path[0])
155155
return a_project['id']
156156

157-
def copyTCnewVersion(self, origTestCaseId, **changedAttributes):
158-
""" creates a new version for test case with ID ORIGTESTCASEID
157+
def copyTCnewVersion(self, origTestCaseId, origVersion=None, **changedAttributes):
158+
""" creates a new version for test case ORIGTESTCASEID
159159
160+
ORIGVERSION specifies the test case version, which should be copied,
161+
default is the max version number
162+
160163
if the new version should differ from the original test case, changed
161164
api arguments could be defined as key value pairs.
162165
Example for changed summary and importance:
163166
- copyTCnewVersion('4711', summary = 'The summary has changed',
164167
importance = '1')
168+
Remarks for some special keys:
169+
'steps': must be a complete list of all steps, changed and unchanged steps
170+
Maybe its better to change the steps in a separat call using
171+
createTestCaseSteps with action='update'.
165172
"""
166173

167-
return self._copyTC(origTestCaseId, changedAttributes,
174+
return self._copyTC(origTestCaseId, changedAttributes, origVersion,
168175
duplicateaction = 'create_new_version')
169176

170-
def copyTCnewTestCase(self, origTestCaseId, **changedAttributes):
171-
""" creates a test case with values from test case with ID ORIGTESTCASEID
177+
def copyTCnewTestCase(self, origTestCaseId, origVersion=None, **changedAttributes):
178+
""" creates a test case with values from test case ORIGTESTCASEID
179+
180+
ORIGVERSION specifies the test case version, which should be copied,
181+
default is the max version number
172182
173183
if the new test case should differ from the original test case, changed
174184
api arguments could be defined as key value pairs.
175185
Example for changed test suite and importance:
176186
- copyTCnewTestCaseVersion('4711', testsuiteid = '1007',
177187
importance = '1')
188+
189+
Remarks for some special keys:
190+
'testsuiteid': defines, in which test suite the TC-copy is inserted.
191+
Default is the same test suite as the original test case.
192+
'steps': must be a complete list of all steps, changed and unchanged steps
193+
Maybe its better to change the steps in a separat call using
194+
createTestCaseSteps with action='update'.
195+
178196
"""
179197

180-
return self._copyTC(origTestCaseId, changedAttributes,
198+
return self._copyTC(origTestCaseId, changedAttributes, origVersion,
181199
duplicateaction = 'generate_new')
182200

183201

184-
def _copyTC(self, origTestCaseId, changedArgs, **options):
202+
def _copyTC(self, origTestCaseId, changedArgs, origVersion=None, **options):
185203
""" creates a copy of test case with id ORIGTESTCASEID
186204
187205
returns createTestCase response for the copy
@@ -195,14 +213,17 @@ def _copyTC(self, origTestCaseId, changedArgs, **options):
195213
'steps': must be a complete list of all steps, changed and unchanged steps
196214
Maybe its better to change the steps in a separat call using
197215
createTestCaseSteps with action='update'.
216+
217+
ORIGVERSION specifies the test case version, which should be copied,
218+
default is the max version number
198219
199220
OPTIONS are optional key value pairs to influence the copy process
200221
- details see comments _copyTCbuildArgs()
201222
202223
"""
203224

204225
# get orig test case content
205-
origArgItems = self.getTestCase(testcaseid=origTestCaseId)[0]
226+
origArgItems = self.getTestCase(origTestCaseId, version=origVersion)[0]
206227
# get orig test case project id
207228
origArgItems['testprojectid'] = self.getProjectIDByNode(origTestCaseId)
208229

test/utest-offline/testlinkapi_offline_test.py

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,37 @@
9696
'id': '26', 'tsuite_name': 'AA - Second Level',
9797
'name': 'TESTCASE_AA'}]},
9898
'getTestCase' : {
99-
'26' : [{'full_tc_external_id': 'NPROAPI-1-26', 'node_order': '0', 'is_open': '1', 'id': '26',
99+
'26-1' : [{'full_tc_external_id': 'NPROAPI-1', 'node_order': '0', 'is_open': '1', 'id': '27',
100100
'author_last_name': 'LkaTlinkD7', 'updater_login': '', 'layout': '1', 'tc_external_id': '1',
101101
'version': '1', 'estimated_exec_duration': '', 'testsuite_id': '25', 'updater_id': '',
102-
'status': '1', 'updater_first_name': '', 'testcase_id': '5099', 'author_first_name': 'Tester',
103-
'importance': '2', 'modification_ts': '', 'execution_type': '1', 'preconditions': '',
102+
'status': '1', 'updater_first_name': '', 'testcase_id': '26', 'author_first_name': 'Tester',
103+
'importance': '2', 'modification_ts': '', 'execution_type': '1', 'preconditions': 'V1',
104104
'active': '1', 'creation_ts': '2013-12-26 21:17:43', 'name': 'TC-C', 'summary': 'SumSumSum',
105105
'updater_last_name': '',
106+
'steps': [{'step_number': '1', 'actions': 'Step action 1', 'execution_type': '2', 'active': '1',
107+
'id': '5101', 'expected_results': 'Step result 1'}],
108+
'author_id': '3', 'author_login': 'tester'}],
109+
'26-2' : [{'full_tc_external_id': 'NPROAPI-1', 'node_order': '0', 'is_open': '1', 'id': '127',
110+
'author_last_name': 'LkaTlinkD7', 'updater_login': '', 'layout': '1', 'tc_external_id': '1',
111+
'version': '2', 'estimated_exec_duration': '', 'testsuite_id': '25', 'updater_id': '',
112+
'status': '1', 'updater_first_name': '', 'testcase_id': '26', 'author_first_name': 'Tester',
113+
'importance': '2', 'modification_ts': '', 'execution_type': '1', 'preconditions': 'V2',
114+
'active': '1', 'creation_ts': '2013-12-26 22:17:43', 'name': 'TC-C', 'summary': 'SumSumSum',
115+
'updater_last_name': '',
116+
'steps': [{'step_number': '1', 'actions': 'Step action 1', 'execution_type': '2', 'active': '1',
117+
'id': '5101', 'expected_results': 'Step result 1'}],
118+
'author_id': '3', 'author_login': 'tester'}],
119+
'26-None' : [{'full_tc_external_id': 'NPROAPI-1', 'node_order': '0', 'is_open': '1', 'id': '127',
120+
'author_last_name': 'LkaTlinkD7', 'updater_login': '', 'layout': '1', 'tc_external_id': '1',
121+
'version': '2', 'estimated_exec_duration': '', 'testsuite_id': '25', 'updater_id': '',
122+
'status': '1', 'updater_first_name': '', 'testcase_id': '26', 'author_first_name': 'Tester',
123+
'importance': '2', 'modification_ts': '', 'execution_type': '1', 'preconditions': 'V2 None',
124+
'active': '1', 'creation_ts': '2013-12-26 22:17:43', 'name': 'TC-C', 'summary': 'SumSumSum',
125+
'updater_last_name': '',
106126
'steps': [{'step_number': '1', 'actions': 'Step action 1', 'execution_type': '2', 'active': '1',
107127
'id': '5101', 'expected_results': 'Step result 1'}],
108128
'author_id': '3', 'author_login': 'tester'}]
129+
109130
},
110131
'getFullPath' : {
111132

@@ -159,7 +180,7 @@ def _callServer(self, methodAPI, argsAPI=None):
159180
elif methodAPI in ['getTestCaseIDByName']:
160181
response = data[argsAPI['testcasename']]
161182
elif methodAPI in ['getTestCase']:
162-
response = data[argsAPI['testcaseid']]
183+
response = data['%(testcaseid)s-%(version)s' % argsAPI]
163184
elif methodAPI in ['getFullPath']:
164185
response = data[argsAPI['nodeid']]
165186
elif methodAPI in ['getTestProjectByName']:
@@ -300,6 +321,7 @@ def test__copyTC_create_new_version(self):
300321
self.api._copyTC('26', {}, duplicateaction = 'create_new_version')
301322
self.assertEqual('create_new_version',
302323
self.api.callArgs['actiononduplicatedname'])
324+
self.assertEqual('V2 None', self.api.callArgs['preconditions'])
303325

304326
def test__copyTC_changedArgs(self):
305327
self.api.loadScenario(SCENARIO_A)
@@ -308,24 +330,56 @@ def test__copyTC_changedArgs(self):
308330
self.assertEqual('4711', self.api.callArgs['testsuiteid'])
309331
self.assertEqual('2211', self.api.callArgs['testprojectid'])
310332

333+
def test__copyTC_changedArgs_version(self):
334+
self.api.loadScenario(SCENARIO_A)
335+
self.api._copyTC('26', {'testsuiteid' :'4711'}, 1,
336+
duplicateaction = 'generate_new')
337+
self.assertEqual('4711', self.api.callArgs['testsuiteid'])
338+
self.assertEqual('2211', self.api.callArgs['testprojectid'])
339+
self.assertEqual('V1', self.api.callArgs['preconditions'])
340+
341+
311342
def test_copyTCnewVersion(self):
312343
self.api.loadScenario(SCENARIO_A)
313344
self.api.copyTCnewVersion('26', summary = 'The summary has changed',
314345
importance = '33')
315346
self.assertEqual('create_new_version',
316347
self.api.callArgs['actiononduplicatedname'])
348+
self.assertEqual('V2 None', self.api.callArgs['preconditions'])
317349
self.assertEqual('The summary has changed', self.api.callArgs['summary'])
318350
self.assertEqual('33', self.api.callArgs['importance'])
319351
self.assertEqual('TC-C', self.api.callArgs['testcasename'])
320352
self.assertEqual('25', self.api.callArgs['testsuiteid'])
321353
self.assertEqual('21', self.api.callArgs['testprojectid'])
322354

355+
def test_copyTCnewVersion_version(self):
356+
self.api.loadScenario(SCENARIO_A)
357+
self.api.copyTCnewVersion('26', 1, summary = 'The summary has changed',
358+
importance = '33')
359+
self.assertEqual('create_new_version',
360+
self.api.callArgs['actiononduplicatedname'])
361+
self.assertEqual('V1', self.api.callArgs['preconditions'])
362+
self.assertEqual('The summary has changed', self.api.callArgs['summary'])
363+
self.assertEqual('33', self.api.callArgs['importance'])
364+
self.assertEqual('TC-C', self.api.callArgs['testcasename'])
365+
self.assertEqual('25', self.api.callArgs['testsuiteid'])
366+
self.assertEqual('21', self.api.callArgs['testprojectid'])
323367

324368
def test_copyTCnewTestCase(self):
325369
self.api.loadScenario(SCENARIO_A)
326370
self.api.copyTCnewTestCase('26', testsuiteid = '4711')
327371
self.assertEqual('generate_new',
328372
self.api.callArgs['actiononduplicatedname'])
373+
self.assertEqual('V2 None', self.api.callArgs['preconditions'])
374+
self.assertEqual('4711', self.api.callArgs['testsuiteid'])
375+
self.assertEqual('2211', self.api.callArgs['testprojectid'])
376+
377+
def test_copyTCnewTestCase_version(self):
378+
self.api.loadScenario(SCENARIO_A)
379+
self.api.copyTCnewTestCase('26', 1, testsuiteid = '4711')
380+
self.assertEqual('generate_new',
381+
self.api.callArgs['actiononduplicatedname'])
382+
self.assertEqual('V1', self.api.callArgs['preconditions'])
329383
self.assertEqual('4711', self.api.callArgs['testsuiteid'])
330384
self.assertEqual('2211', self.api.callArgs['testprojectid'])
331385

0 commit comments

Comments
 (0)