Skip to content

Commit dffd8f8

Browse files
author
Luiko Czub
committed
new service methods listKeywordsForTC() #25
new TestlinkAPIClient service method listKeywordsForTC(internal_or_external_tc_id) returns a keyword list without internal details (like getTestCasesForTestSuite() does)
1 parent c43eed7 commit dffd8f8

File tree

5 files changed

+130
-6
lines changed

5 files changed

+130
-6
lines changed

Diff for: CHANGES.rst

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,39 @@
11
Changes in TestLink-API-Python-client Source Distribution
22
=========================================================
33

4-
TestLink-API-Python-client UNDER DEVELOP v0.4.9
4+
TestLink-API-Python-client UNDER DEVELOP v0.5.0
55
-----------------------------------------------------------
66

7+
new service methods - list keywords #25 UNDER DEVELOP
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
new TestlinkAPIClient service methods, which returns a keyword list without
11+
internal details (like getTestCasesForTestSuite() does)
12+
13+
- listKeywordsForTC(internal_or_external_tc_id)
14+
- listKeywordsForTC(ts_id) !!NOT YET IMPLEMENTET!!
15+
16+
Example::
17+
18+
>>> import testlink
19+
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
20+
>>> tls.getTestCase(None, testcaseexternalid='NPROAPI-3')
21+
>>> tc_kw = tls.listKeywordsForTC('NPROAPI-3')
22+
['KeyWord01', 'KeyWord03']
23+
>>> tc_kw = tls.listKeywordsForTC(5440)
24+
['KeyWord01', 'KeyWord03']
25+
>>> tc_kw = tls.listKeywordsForTC('5440')
26+
['KeyWord01', 'KeyWord03']
27+
>>> ts_kw = tls.listKeywordsForTS('5415')
28+
{'NPROAPI-3' : ['KeyWord01', 'KeyWord03'], 'NPROAPI-1' : ['KeyWord03'],
29+
'NPROAPI-2' : []}
30+
31+
32+
Known limitations:
33+
34+
- it is not possible to ask for a special test case version, cause TL links
35+
keywords against a test case and not a test case version
36+
737
implement 1.9.10 api change - getTestCasesForTestSuite #23
838
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
939

Diff for: example/TestLinkExampleCustomFields.py

+4
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@
151151
newTestCase_B = myTestLink.getTestCase(testcaseid=newTestCaseID_B)[0]
152152
print "getTestCase", newTestCase_B
153153

154+
# return keyword list for TestCase_B
155+
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
156+
print "listKeywordsForTC", response
157+
154158

155159
# new execution result with custom field data
156160
# TC_B passed, explicit build and some notes , TC identified with internal id

Diff for: src/testlink/testlinkapi.py

+43
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,49 @@ def _copyTCbuildArgs(self, origArgItems, changedArgs, options):
293293

294294
return (posArgValues, newArgItems)
295295

296+
#
297+
# ADDITIONNAL FUNCTIONS- keywords
298+
#
299+
300+
def listKeywordsForTC(self, internal_or_external_tc_id):
301+
""" Returns list with keyword for a test case
302+
INTERNAL_OR_EXTERNAL_TC_ID defines
303+
- either the internal test case ID (8111 or '8111')
304+
- or the full external test case ID ('NPROAPI-2')
305+
306+
Attention:
307+
- the tcversion_id is not supported
308+
- it is not possible to ask for a special test case version, cause TL
309+
links keywords against a test case and not a test case version
310+
"""
311+
312+
a_tc_id = str(internal_or_external_tc_id)
313+
argsPositional = [a_tc_id]
314+
argsOptional = {}
315+
if '-' in a_tc_id:
316+
# full external ID like 'NPROAPI-2'
317+
argsPositional = [None]
318+
argsOptional = {'testcaseexternalid' : a_tc_id}
319+
a_tc = self.getTestCase(*argsPositional, **argsOptional)[0]
320+
a_ts_id = a_tc['testsuite_id']
321+
# attention!
322+
# don't use 'id', that is the tcversion_id
323+
# - table tcversions, field id
324+
# use testcase_id, that is id test case id without a version info
325+
# - table nodes_hierarchy, fied id (condition node_type_id == 3)
326+
a_tc_id = a_tc['testcase_id']
327+
all_tc_for_ts = self.getTestCasesForTestSuite(a_ts_id, False,
328+
'full', getkeywords=True)
329+
330+
keyword_details = {}
331+
332+
for a_ts_tc in all_tc_for_ts:
333+
if a_ts_tc['id'] == a_tc_id:
334+
keyword_details = a_ts_tc.get('keywords', {})
335+
336+
keywords = map((lambda x: x['keyword']), keyword_details.values())
337+
return keywords
338+
296339
#
297340
# ADDITIONNAL FUNCTIONS
298341
#

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.5.0-Beta'
20+
VERSION = '0.5.0-dev25'

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

+51-4
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@
188188
{'step_number': '7', 'actions': 'action 7 createTestCaseSteps.create', 'execution_type': '2', 'active': '1', 'id': '8157', 'expected_results': 'create - cause step 7 not yet exist'},
189189
{'step_number': '8', 'actions': 'action 8 createTestCaseSteps.update', 'execution_type': '2', 'active': '1', 'id': '8158', 'expected_results': 'create - cause step 8 not yet exist'}],
190190
'author_id': '1'},
191-
{'node_order': '1', 'is_open': '1',
191+
{'node_order': '1', 'is_open': '1',
192192
'keywords': {'2': {'keyword_id': '2', 'notes': 'another key word', 'testcase_id': '8159', 'keyword': 'KeyWord02'}},
193193
'id': '8159', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '3', 'parent_id': '8134', 'version': '1',
194194
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
@@ -199,7 +199,7 @@
199199
'steps': [{'step_number': '1', 'actions': '<p>\n\tStep action 1 -b2</p>\n', 'execution_type': '2', 'active': '1', 'id': '8161', 'expected_results': '<p>\n\tStep result 1 - b2</p>\n'},
200200
{'step_number': '2', 'actions': '<p>\n\tStep action 2 -b2</p>\n', 'execution_type': '2', 'active': '1', 'id': '8162', 'expected_results': '<p>\n\tStep result 2 - b2</p>\n'}],
201201
'author_id': '2'},
202-
{'node_order': '2', 'is_open': '1',
202+
{'node_order': '2', 'is_open': '1',
203203
'id': '8169', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '4', 'parent_id': '8134', 'version': '1',
204204
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
205205
'importance': '3', 'modification_ts': '2014-07-02 21:02:23', 'execution_type': '1',
@@ -209,7 +209,20 @@
209209
'steps': [{'step_number': '1', 'actions': '<p>\n\tStep action 1 -b3</p>\n', 'execution_type': '2', 'active': '1', 'id': '8171', 'expected_results': '<p>\n\tStep result 1 - b3</p>\n'},
210210
{'step_number': '2', 'actions': '<p>\n\tStep action 2 -b3</p>\n', 'execution_type': '2', 'active': '1', 'id': '8172', 'expected_results': '<p>\n\tStep result 2 - b3</p>\n'}],
211211
'author_id': '2'}]
212-
}
212+
},
213+
'getTestCase' : {
214+
'8144' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
215+
'testsuite_id': 'deepFalse3', 'testcase_id': '8144', 'name': 'TESTCASE_B'}],
216+
'NPROAPI-2' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
217+
'testsuite_id': 'deepFalse3', 'testcase_id': '8144', 'name': 'TESTCASE_B'}],
218+
'8159' : [{'full_tc_external_id': 'NPROAPI-3', 'id': '8160', 'tc_external_id': '3', 'version': '1',
219+
'testsuite_id': 'deepFalse3', 'testcase_id': '8159', 'name': 'TESTCASE_B2'}],
220+
'NPROAPI-3' : [{'full_tc_external_id': 'NPROAPI-3', 'id': '8160', 'tc_external_id': '3', 'version': '1',
221+
'testsuite_id': 'deepFalse3', 'testcase_id': '8159', 'name': 'TESTCASE_B2'}],
222+
'8169' : [{'full_tc_external_id': 'NPROAPI-4', 'id': '8170', 'tc_external_id': '3', 'version': '1',
223+
'testsuite_id': 'deepFalse3', 'testcase_id': '8169', 'name': 'TESTCASE_B3'}],
224+
'NPROAPI-4' : [{'full_tc_external_id': 'NPROAPI-4', 'id': '8170', 'tc_external_id': '3', 'version': '1',
225+
'testsuite_id': 'deepFalse3', 'testcase_id': '8169', 'name': 'TESTCASE_B3'}] }
213226
}
214227

215228

@@ -245,7 +258,14 @@ def _callServer(self, methodAPI, argsAPI=None):
245258
elif methodAPI in ['getTestCaseIDByName']:
246259
response = data[argsAPI['testcasename']]
247260
elif methodAPI in ['getTestCase']:
248-
response = data['%(testcaseid)s-%(version)s' % argsAPI]
261+
datakey = argsAPI.get('testcaseid')
262+
if datakey:
263+
datakey = str(datakey)
264+
else:
265+
datakey = argsAPI.get('testcaseexternalid', '')
266+
if argsAPI.has_key('version'):
267+
datakey += '-%(version)s' % argsAPI
268+
response = data[datakey]
249269
elif methodAPI in ['getFullPath']:
250270
response = data[argsAPI['nodeid']]
251271
elif methodAPI in ['getTestProjectByName']:
@@ -472,6 +492,33 @@ def test_whatArgs_getTestCasesForTestSuite(self):
472492
argsDescription = self.api.whatArgs('getTestCasesForTestSuite')
473493
self.assertIn('getkeywords=<getkeywords>', argsDescription)
474494

495+
def test_listKeywordsForTC_FullExternalId(self):
496+
self.api.loadScenario(SCENARIO_KEYWORDS)
497+
response = self.api.listKeywordsForTC('NPROAPI-2')
498+
self.assertEqual(['KeyWord01', 'KeyWord03'], response)
499+
500+
def test_listKeywordsForTC_InternalId_Int(self):
501+
self.api.loadScenario(SCENARIO_KEYWORDS)
502+
response = self.api.listKeywordsForTC(8144)
503+
self.assertEqual(['KeyWord01', 'KeyWord03'], response)
504+
505+
def test_listKeywordsForTC_InternalId_String(self):
506+
self.api.loadScenario(SCENARIO_KEYWORDS)
507+
response = self.api.listKeywordsForTC('8144')
508+
self.assertEqual(['KeyWord01', 'KeyWord03'], response)
509+
510+
def test_listKeywordsForTC_One(self):
511+
self.api.loadScenario(SCENARIO_KEYWORDS)
512+
response = self.api.listKeywordsForTC('NPROAPI-3')
513+
self.assertEqual(['KeyWord02'], response)
514+
515+
def test_listKeywordsForTC_None(self):
516+
self.api.loadScenario(SCENARIO_KEYWORDS)
517+
response = self.api.listKeywordsForTC('NPROAPI-4')
518+
self.assertEqual([], response)
519+
520+
521+
475522

476523

477524
if __name__ == "__main__":

0 commit comments

Comments
 (0)