@@ -145,75 +145,132 @@ def createTestCase(self, *argsPositional, **argsOptional):
145
145
# ADDITIONNAL FUNCTIONS- copy test cases
146
146
#
147
147
148
- def _copyTC (self , origTestCaseId , duplicateaction , changedArguments ):
148
+ def getProjectIDByNode (self , a_nodeid ):
149
+ """ returns project id , the nodeid belongs to."""
150
+
151
+ # get node path
152
+ node_path = self .getFullPath (int (a_nodeid ))[a_nodeid ]
153
+ # get project and id
154
+ a_project = self .getTestProjectByName (node_path [0 ])
155
+ return a_project ['id' ]
156
+
157
+ def copyTCnewVersion (self , origTestCaseId , ** changedAttributes ):
158
+ """ creates a new version for test case with ID ORIGTESTCASEID
159
+
160
+ if the new version should differ from the original test case, changed
161
+ api arguments could be defined as key value pairs.
162
+ Example for changed summary and importance:
163
+ - copyTCnewVersion('4711', summary = 'The summary has changed',
164
+ importance = '1')
165
+ """
166
+
167
+ return self ._copyTC (origTestCaseId , changedAttributes ,
168
+ duplicateaction = 'create_new_version' )
169
+
170
+ def copyTCnewTestCase (self , origTestCaseId , ** changedAttributes ):
171
+ """ creates a test case with values from test case with ID ORIGTESTCASEID
172
+
173
+ if the new test case should differ from the original test case, changed
174
+ api arguments could be defined as key value pairs.
175
+ Example for changed test suite and importance:
176
+ - copyTCnewTestCaseVersion('4711', testsuiteid = '1007',
177
+ importance = '1')
178
+ """
179
+
180
+ return self ._copyTC (origTestCaseId , changedAttributes ,
181
+ duplicateaction = 'generate_new' )
182
+
183
+
184
+ def _copyTC (self , origTestCaseId , changedArgs , ** options ):
149
185
""" creates a copy of test case with id ORIGTESTCASEID
150
186
151
- DUPLICATEACTION decides, how the the test case copy (TC-copy) is
152
- inserted
153
- 'generate_new': a separate new test case is created, even if name
154
- and test suite are equal
155
- 'create_new_version': if the target test suite includes already a
156
- test case with the same name, a new version is created.
157
- if the target test suite includes not a test case with the defined
158
- name, a new test case with version 1 is created
159
-
160
- CHANGEDARGUMENTS defines a dictionary with key value pairs, the api
161
- arguments, expected from createTestCase.
162
- Only arguments, which differ between the original and the
163
- copy must be defined here
164
- Remarks for some special keys:
165
- 'testsuiteid': defines, in which test suite the TC-copy is inserted.
166
- Default is the same test suite as the original test case.
167
- 'steps': must be a complete list of all steps, changed and unchanged steps
168
- Maybe its better to change the steps in a separat call using
169
- createTestCaseSteps with action='update'.
187
+ returns createTestCase response for the copy
188
+
189
+ CHANGEDARGUMENTS defines a dictionary with api arguments, expected from
190
+ createTestCase. Only arguments, which differ between TC-orig
191
+ and TC-copy must be defined
192
+ Remarks for some special keys:
193
+ 'testsuiteid': defines, in which test suite the TC-copy is inserted.
194
+ Default is the same test suite as the original test case.
195
+ 'steps': must be a complete list of all steps, changed and unchanged steps
196
+ Maybe its better to change the steps in a separat call using
197
+ createTestCaseSteps with action='update'.
198
+
199
+ OPTIONS are optional key value pairs to influence the copy process
200
+ - details see comments _copyTCbuildArgs()
170
201
171
202
"""
172
203
173
- # (tcase_id, tcase_ext_id) = newProj(projKey, 'duplicate Test Case')
174
204
# get orig test case content
175
205
origArgItems = self .getTestCase (testcaseid = origTestCaseId )[0 ]
176
- print 'getTestCase' , origArgItems
177
- # get orig test case path
178
- origPath = self .getFullPath (int (origTestCaseId ))[origTestCaseId ]
179
- print 'getFullPath' , origPath
180
- # get orig test case project
181
- origProject = self .getTestProjectByName (origPath [0 ])
182
- print 'origProject' , origProject
206
+ # get orig test case project id
207
+ origArgItems ['testprojectid' ] = self .getProjectIDByNode (origTestCaseId )
183
208
184
- # extend origItems with some default values
185
- # testprojectid, mandatory in createTestCase
186
- origArgItems ['testprojectid' ] = origProject ['id' ]
187
- origArgItems ['checkduplicatedname' ] = 1
188
- # origArgItems['actiononduplicatedname'] = 'create_new_version'
189
- origArgItems ['actiononduplicatedname' ] = duplicateaction
209
+ # build args for the TC-copy
210
+ (posArgValues , newArgItems ) = self ._copyTCbuildArgs (origArgItems ,
211
+ changedArgs , options )
212
+ # create the TC-Copy
213
+ response = self .createTestCase (* posArgValues , ** newArgItems )
214
+ return response
215
+
216
+ def _copyTCbuildArgs (self , origArgItems , changedArgs , options ):
217
+ """ build Args to create a new test case .
218
+ ORIGARGITEMS is a dictionary with getTestCase response of an existing
219
+ test case
220
+ CHANGEDARGS is a dictionary with api argument for createTestCase, which
221
+ should differ from these
222
+ OPTIONS is a dictionary with settings for the copy process
190
223
191
- # collect info, which arguments are needed from orig test case
224
+ 'duplicateaction': decides, how the TC-copy is inserted
225
+ - 'generate_new' (default): a separate new test case is created, even
226
+ if name and test suite are equal
227
+ - 'create_new_version': if the target test suite includes already a
228
+ test case with the same name, a new version is created.
229
+ if the target test suite includes not a test case with the
230
+ defined name, a new test case with version 1 is created
231
+ """
232
+
233
+ # collect info, which arguments createTestCase expects
192
234
(posArgNames , optArgNames , manArgNames ) = \
193
235
self ._apiMethodArgNames ('createTestCase' )
194
236
# some argNames not realy needed
195
237
optArgNames .remove ('internalid' )
196
238
optArgNames .remove ('devKey' )
197
239
240
+ # mapping between getTestCase response and createTestCase arg names
198
241
externalArgNames = posArgNames [:]
199
242
externalArgNames .extend (optArgNames )
200
- externalTointernalNames = {'testcasename' : 'name' , 'testsuiteid' : 'testsuite_id' ,
201
- 'authorlogin' : 'author_login' , 'execution' : 'execution_type' ,
202
- 'order' : 'node_order' }
243
+ externalTointernalNames = {'testcasename' : 'name' ,
244
+ 'testsuiteid' : 'testsuite_id' , 'authorlogin' : 'author_login' ,
245
+ 'execution' : 'execution_type' , 'order' : 'node_order' }
246
+
247
+ # extend origItems with some values needed in createTestCase
248
+ origArgItems ['checkduplicatedname' ] = 1
249
+ origArgItems ['actiononduplicatedname' ] = options .get ('duplicateaction' ,
250
+ 'generate_new' )
251
+ # build arg dictionary for TC-copy with orig values
203
252
newArgItems = {}
204
253
for exArgName in externalArgNames :
205
254
inArgName = externalTointernalNames .get (exArgName , exArgName )
206
255
newArgItems [exArgName ] = origArgItems [inArgName ]
256
+
257
+ # if changed values defines a different test suite, add the correct
258
+ # project id
259
+ if changedArgs .has_key ('testsuiteid' ):
260
+ changedProjID = self .getProjectIDByNode (changedArgs ['testsuiteid' ])
261
+ changedArgs ['testprojectid' ] = changedProjID
207
262
263
+ # change orig values for TC-copy
264
+ for (argName , argValue ) in changedArgs .items ():
265
+ newArgItems [argName ] = argValue
266
+
267
+ # separate positional and optional createTestCase arguments
208
268
posArgValues = []
209
269
for argName in posArgNames :
210
270
posArgValues .append (newArgItems [argName ])
211
271
newArgItems .pop (argName )
212
-
213
- print 'posArgValues' , posArgValues
214
- print 'newArgItems' , newArgItems
215
- response = self .createTestCase (* posArgValues , ** newArgItems )
216
- print 'createTestCase' , response
272
+
273
+ return (posArgValues , newArgItems )
217
274
218
275
#
219
276
# ADDITIONNAL FUNCTIONS
0 commit comments