Skip to content

Commit 5f8ce98

Browse files
author
Luiko Czub
committed
new service methods listKeywordsForTS() #25
new TestlinkAPIClient service method listKeywordsForTC(internal_ts_id) Returns dictionary with keyword lists for all test cases of a test suite without internal details (like getTestCasesForTestSuite() does)
1 parent dffd8f8 commit 5f8ce98

File tree

4 files changed

+77
-9
lines changed

4 files changed

+77
-9
lines changed

CHANGES.rst

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Changes in TestLink-API-Python-client Source Distribution
44
TestLink-API-Python-client UNDER DEVELOP v0.5.0
55
-----------------------------------------------------------
66

7-
new service methods - list keywords #25 UNDER DEVELOP
8-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
new service methods - list keywords #25
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99

10-
new TestlinkAPIClient service methods, which returns a keyword list without
10+
new TestlinkAPIClient service methods, which returns keyword lists without
1111
internal details (like getTestCasesForTestSuite() does)
1212

1313
- listKeywordsForTC(internal_or_external_tc_id)
14-
- listKeywordsForTC(ts_id) !!NOT YET IMPLEMENTET!!
14+
- listKeywordsForTC(internal_ts_id)
1515

1616
Example::
1717

@@ -25,8 +25,7 @@ Example::
2525
>>> tc_kw = tls.listKeywordsForTC('5440')
2626
['KeyWord01', 'KeyWord03']
2727
>>> ts_kw = tls.listKeywordsForTS('5415')
28-
{'NPROAPI-3' : ['KeyWord01', 'KeyWord03'], 'NPROAPI-1' : ['KeyWord03'],
29-
'NPROAPI-2' : []}
28+
{'5440' : ['KeyWord01', 'KeyWord03'], '5445' : ['KeyWord03'], '5450' : []}
3029
3130
3231
Known limitations:

example/TestLinkExampleCustomFields.py

+7-2
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,10 @@
141141
# list test cases with assigned keywords
142142
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, True,
143143
'full', getkeywords=True)
144-
print "getTestCasesForTestSuite", response
144+
print "getTestCasesForTestSuite (deep=True)", response
145+
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False,
146+
'full', getkeywords=True)
147+
print "getTestCasesForTestSuite (deep=False)", response
145148

146149
# get informationen - TestCase_B
147150
response = myTestLink.getTestCaseIDByName(NEWTESTCASE_B, testprojectname=NEWPROJECT)
@@ -154,7 +157,9 @@
154157
# return keyword list for TestCase_B
155158
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
156159
print "listKeywordsForTC", response
157-
160+
# return keyword lists for all test cases of test newTestSuite_B
161+
response = myTestLink.listKeywordsForTS(newTestSuiteID_B)
162+
print "listKeywordsForTS", response
158163

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

src/testlink/testlinkapi.py

+17
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,23 @@ def listKeywordsForTC(self, internal_or_external_tc_id):
336336
keywords = map((lambda x: x['keyword']), keyword_details.values())
337337
return keywords
338338

339+
def listKeywordsForTS(self, internal_ts_id):
340+
""" Returns dictionary with keyword lists for all test cases of
341+
test suite with id == INTERNAL_TS_ID
342+
"""
343+
344+
a_ts_id = str(internal_ts_id)
345+
all_tc_for_ts = self.getTestCasesForTestSuite(a_ts_id, False,
346+
'full', getkeywords=True)
347+
response = {}
348+
for a_ts_tc in all_tc_for_ts:
349+
tc_id = a_ts_tc['id']
350+
keyword_details = a_ts_tc.get('keywords', {})
351+
keywords = map((lambda x: x['keyword']), keyword_details.values())
352+
response[tc_id] = keywords
353+
354+
return response
355+
339356
#
340357
# ADDITIONNAL FUNCTIONS
341358
#

test/utest-offline/testlinkapi_offline_test.py

+48-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,30 @@
208208
'summary': '<p>\n\tThis is the summary of the Test Case B3</p>\n',
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'}],
211-
'author_id': '2'}]
211+
'author_id': '2'}],
212+
213+
'4711' : [{'node_order': '0', 'is_open': '1',
214+
'keywords': {'1': {'keyword_id': '1', 'notes': 'a key word', 'testcase_id': '8144', 'keyword': 'KeyWord01'},
215+
'3': {'keyword_id': '3', 'notes': 'a third key word', 'testcase_id': '8144', 'keyword': 'KeyWord03'}},
216+
'id': '8144', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '2', 'parent_id': '8134', 'version': '1',
217+
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
218+
'importance': '3', 'modification_ts': '2014-06-30 20:45:40', 'execution_type': '1',
219+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
220+
'node_table': 'testcases', 'tcversion_id': '8145', 'name': 'TESTCASE_B',
221+
'summary': '<p>\n\tThis is the summary of the Test Case B</p>\n',
222+
'steps': [{'step_number': '1', 'actions': 'Step action 1 -b ', 'execution_type': '2', 'active': '1', 'id': '8151', 'expected_results': 'Step result 1 - b'}],
223+
'author_id': '1'} ],
224+
225+
'noKeywords' : [{'node_order': '0', 'is_open': '1',
226+
'id': '8144', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '2', 'parent_id': '8134', 'version': '1',
227+
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
228+
'importance': '3', 'modification_ts': '2014-06-30 20:45:40', 'execution_type': '1',
229+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
230+
'node_table': 'testcases', 'tcversion_id': '8145', 'name': 'TESTCASE_B',
231+
'summary': '<p>\n\tThis is the summary of the Test Case B</p>\n',
232+
'steps': [{'step_number': '1', 'actions': 'Step action 1 -b ', 'execution_type': '2', 'active': '1', 'id': '8151', 'expected_results': 'Step result 1 - b'}],
233+
'author_id': '1'} ]
234+
212235
},
213236
'getTestCase' : {
214237
'8144' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
@@ -517,7 +540,31 @@ def test_listKeywordsForTC_None(self):
517540
response = self.api.listKeywordsForTC('NPROAPI-4')
518541
self.assertEqual([], response)
519542

543+
def test_listKeywordsForTS_NoneTC(self):
544+
self.api.loadScenario(SCENARIO_KEYWORDS)
545+
response = self.api.listKeywordsForTS('noTestCase')
546+
self.assertEqual({}, response)
547+
548+
def test_listKeywordsForTS_NoneKW(self):
549+
self.api.loadScenario(SCENARIO_KEYWORDS)
550+
response = self.api.listKeywordsForTS('noKeywords')
551+
self.assertEqual({'8144' : []}, response)
552+
553+
def test_listKeywordsForTS_Id_Int(self):
554+
self.api.loadScenario(SCENARIO_KEYWORDS)
555+
response = self.api.listKeywordsForTS(4711)
556+
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)
520557

558+
def test_listKeywordsForTS_Id_String(self):
559+
self.api.loadScenario(SCENARIO_KEYWORDS)
560+
response = self.api.listKeywordsForTS('4711')
561+
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)
562+
563+
def test_listKeywordsForTS_Multi(self):
564+
self.api.loadScenario(SCENARIO_KEYWORDS)
565+
response = self.api.listKeywordsForTS('deepFalse3')
566+
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03'],
567+
'8159' : ['KeyWord02'], '8169' : []}, response)
521568

522569

523570

0 commit comments

Comments
 (0)