Skip to content

Commit

Permalink
new service methods listKeywordsForTS() #25
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
Luiko Czub committed Jul 23, 2014
1 parent dffd8f8 commit 5f8ce98
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 9 deletions.
11 changes: 5 additions & 6 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ Changes in TestLink-API-Python-client Source Distribution
TestLink-API-Python-client UNDER DEVELOP v0.5.0
-----------------------------------------------------------

new service methods - list keywords #25 UNDER DEVELOP
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
new service methods - list keywords #25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

new TestlinkAPIClient service methods, which returns a keyword list without
new TestlinkAPIClient service methods, which returns keyword lists without
internal details (like getTestCasesForTestSuite() does)

- listKeywordsForTC(internal_or_external_tc_id)
- listKeywordsForTC(ts_id) !!NOT YET IMPLEMENTET!!
- listKeywordsForTC(internal_ts_id)

Example::

Expand All @@ -25,8 +25,7 @@ Example::
>>> tc_kw = tls.listKeywordsForTC('5440')
['KeyWord01', 'KeyWord03']
>>> ts_kw = tls.listKeywordsForTS('5415')
{'NPROAPI-3' : ['KeyWord01', 'KeyWord03'], 'NPROAPI-1' : ['KeyWord03'],
'NPROAPI-2' : []}
{'5440' : ['KeyWord01', 'KeyWord03'], '5445' : ['KeyWord03'], '5450' : []}
Known limitations:
Expand Down
9 changes: 7 additions & 2 deletions example/TestLinkExampleCustomFields.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,10 @@
# list test cases with assigned keywords
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, True,
'full', getkeywords=True)
print "getTestCasesForTestSuite", response
print "getTestCasesForTestSuite (deep=True)", response
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, False,
'full', getkeywords=True)
print "getTestCasesForTestSuite (deep=False)", response

# get informationen - TestCase_B
response = myTestLink.getTestCaseIDByName(NEWTESTCASE_B, testprojectname=NEWPROJECT)
Expand All @@ -154,7 +157,9 @@
# return keyword list for TestCase_B
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
print "listKeywordsForTC", response

# return keyword lists for all test cases of test newTestSuite_B
response = myTestLink.listKeywordsForTS(newTestSuiteID_B)
print "listKeywordsForTS", response

# new execution result with custom field data
# TC_B passed, explicit build and some notes , TC identified with internal id
Expand Down
17 changes: 17 additions & 0 deletions src/testlink/testlinkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,23 @@ def listKeywordsForTC(self, internal_or_external_tc_id):
keywords = map((lambda x: x['keyword']), keyword_details.values())
return keywords

def listKeywordsForTS(self, internal_ts_id):
""" Returns dictionary with keyword lists for all test cases of
test suite with id == INTERNAL_TS_ID
"""

a_ts_id = str(internal_ts_id)
all_tc_for_ts = self.getTestCasesForTestSuite(a_ts_id, False,
'full', getkeywords=True)
response = {}
for a_ts_tc in all_tc_for_ts:
tc_id = a_ts_tc['id']
keyword_details = a_ts_tc.get('keywords', {})
keywords = map((lambda x: x['keyword']), keyword_details.values())
response[tc_id] = keywords

return response

#
# ADDITIONNAL FUNCTIONS
#
Expand Down
49 changes: 48 additions & 1 deletion test/utest-offline/testlinkapi_offline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,30 @@
'summary': '<p>\n\tThis is the summary of the Test Case B3</p>\n',
'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'},
{'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'}],
'author_id': '2'}]
'author_id': '2'}],

'4711' : [{'node_order': '0', 'is_open': '1',
'keywords': {'1': {'keyword_id': '1', 'notes': 'a key word', 'testcase_id': '8144', 'keyword': 'KeyWord01'},
'3': {'keyword_id': '3', 'notes': 'a third key word', 'testcase_id': '8144', 'keyword': 'KeyWord03'}},
'id': '8144', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '2', 'parent_id': '8134', 'version': '1',
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
'importance': '3', 'modification_ts': '2014-06-30 20:45:40', 'execution_type': '1',
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
'node_table': 'testcases', 'tcversion_id': '8145', 'name': 'TESTCASE_B',
'summary': '<p>\n\tThis is the summary of the Test Case B</p>\n',
'steps': [{'step_number': '1', 'actions': 'Step action 1 -b ', 'execution_type': '2', 'active': '1', 'id': '8151', 'expected_results': 'Step result 1 - b'}],
'author_id': '1'} ],

'noKeywords' : [{'node_order': '0', 'is_open': '1',
'id': '8144', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '2', 'parent_id': '8134', 'version': '1',
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
'importance': '3', 'modification_ts': '2014-06-30 20:45:40', 'execution_type': '1',
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
'node_table': 'testcases', 'tcversion_id': '8145', 'name': 'TESTCASE_B',
'summary': '<p>\n\tThis is the summary of the Test Case B</p>\n',
'steps': [{'step_number': '1', 'actions': 'Step action 1 -b ', 'execution_type': '2', 'active': '1', 'id': '8151', 'expected_results': 'Step result 1 - b'}],
'author_id': '1'} ]

},
'getTestCase' : {
'8144' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
Expand Down Expand Up @@ -517,7 +540,31 @@ def test_listKeywordsForTC_None(self):
response = self.api.listKeywordsForTC('NPROAPI-4')
self.assertEqual([], response)

def test_listKeywordsForTS_NoneTC(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTS('noTestCase')
self.assertEqual({}, response)

def test_listKeywordsForTS_NoneKW(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTS('noKeywords')
self.assertEqual({'8144' : []}, response)

def test_listKeywordsForTS_Id_Int(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTS(4711)
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)

def test_listKeywordsForTS_Id_String(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTS('4711')
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03']}, response)

def test_listKeywordsForTS_Multi(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTS('deepFalse3')
self.assertEqual({'8144' : ['KeyWord01', 'KeyWord03'],
'8159' : ['KeyWord02'], '8169' : []}, response)



Expand Down

0 comments on commit 5f8ce98

Please sign in to comment.