Skip to content

Commit

Permalink
new service methods listKeywordsForTC() #25
Browse files Browse the repository at this point in the history
new TestlinkAPIClient service method
listKeywordsForTC(internal_or_external_tc_id)
returns a keyword list without internal details (like
getTestCasesForTestSuite() does)
  • Loading branch information
Luiko Czub committed Jul 22, 2014
1 parent c43eed7 commit dffd8f8
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 6 deletions.
32 changes: 31 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,39 @@
Changes in TestLink-API-Python-client Source Distribution
=========================================================

TestLink-API-Python-client UNDER DEVELOP v0.4.9
TestLink-API-Python-client UNDER DEVELOP v0.5.0
-----------------------------------------------------------

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

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

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

Example::

>>> import testlink
>>> tls = testlink.TestLinkHelper().connect(testlink.TestlinkAPIClient)
>>> tls.getTestCase(None, testcaseexternalid='NPROAPI-3')
>>> tc_kw = tls.listKeywordsForTC('NPROAPI-3')
['KeyWord01', 'KeyWord03']
>>> tc_kw = tls.listKeywordsForTC(5440)
['KeyWord01', 'KeyWord03']
>>> tc_kw = tls.listKeywordsForTC('5440')
['KeyWord01', 'KeyWord03']
>>> ts_kw = tls.listKeywordsForTS('5415')
{'NPROAPI-3' : ['KeyWord01', 'KeyWord03'], 'NPROAPI-1' : ['KeyWord03'],
'NPROAPI-2' : []}
Known limitations:

- it is not possible to ask for a special test case version, cause TL links
keywords against a test case and not a test case version

implement 1.9.10 api change - getTestCasesForTestSuite #23
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
4 changes: 4 additions & 0 deletions example/TestLinkExampleCustomFields.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@
newTestCase_B = myTestLink.getTestCase(testcaseid=newTestCaseID_B)[0]
print "getTestCase", newTestCase_B

# return keyword list for TestCase_B
response = myTestLink.listKeywordsForTC(newTestCaseID_B)
print "listKeywordsForTC", response


# new execution result with custom field data
# TC_B passed, explicit build and some notes , TC identified with internal id
Expand Down
43 changes: 43 additions & 0 deletions src/testlink/testlinkapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,49 @@ def _copyTCbuildArgs(self, origArgItems, changedArgs, options):

return (posArgValues, newArgItems)

#
# ADDITIONNAL FUNCTIONS- keywords
#

def listKeywordsForTC(self, internal_or_external_tc_id):
""" Returns list with keyword for a test case
INTERNAL_OR_EXTERNAL_TC_ID defines
- either the internal test case ID (8111 or '8111')
- or the full external test case ID ('NPROAPI-2')
Attention:
- the tcversion_id is not supported
- it is not possible to ask for a special test case version, cause TL
links keywords against a test case and not a test case version
"""

a_tc_id = str(internal_or_external_tc_id)
argsPositional = [a_tc_id]
argsOptional = {}
if '-' in a_tc_id:
# full external ID like 'NPROAPI-2'
argsPositional = [None]
argsOptional = {'testcaseexternalid' : a_tc_id}
a_tc = self.getTestCase(*argsPositional, **argsOptional)[0]
a_ts_id = a_tc['testsuite_id']
# attention!
# don't use 'id', that is the tcversion_id
# - table tcversions, field id
# use testcase_id, that is id test case id without a version info
# - table nodes_hierarchy, fied id (condition node_type_id == 3)
a_tc_id = a_tc['testcase_id']
all_tc_for_ts = self.getTestCasesForTestSuite(a_ts_id, False,
'full', getkeywords=True)

keyword_details = {}

for a_ts_tc in all_tc_for_ts:
if a_ts_tc['id'] == a_tc_id:
keyword_details = a_ts_tc.get('keywords', {})

keywords = map((lambda x: x['keyword']), keyword_details.values())
return keywords

#
# ADDITIONNAL FUNCTIONS
#
Expand Down
2 changes: 1 addition & 1 deletion src/testlink/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
#
# ------------------------------------------------------------------------

VERSION = '0.5.0-Beta'
VERSION = '0.5.0-dev25'
55 changes: 51 additions & 4 deletions test/utest-offline/testlinkapi_offline_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@
{'step_number': '7', 'actions': 'action 7 createTestCaseSteps.create', 'execution_type': '2', 'active': '1', 'id': '8157', 'expected_results': 'create - cause step 7 not yet exist'},
{'step_number': '8', 'actions': 'action 8 createTestCaseSteps.update', 'execution_type': '2', 'active': '1', 'id': '8158', 'expected_results': 'create - cause step 8 not yet exist'}],
'author_id': '1'},
{'node_order': '1', 'is_open': '1',
{'node_order': '1', 'is_open': '1',
'keywords': {'2': {'keyword_id': '2', 'notes': 'another key word', 'testcase_id': '8159', 'keyword': 'KeyWord02'}},
'id': '8159', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '3', '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',
Expand All @@ -199,7 +199,7 @@
'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'},
{'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'}],
'author_id': '2'},
{'node_order': '2', 'is_open': '1',
{'node_order': '2', 'is_open': '1',
'id': '8169', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '4', '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-07-02 21:02:23', 'execution_type': '1',
Expand All @@ -209,7 +209,20 @@
'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'}]
}
},
'getTestCase' : {
'8144' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8144', 'name': 'TESTCASE_B'}],
'NPROAPI-2' : [{'full_tc_external_id': 'NPROAPI-2', 'id': '8145', 'tc_external_id': '2', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8144', 'name': 'TESTCASE_B'}],
'8159' : [{'full_tc_external_id': 'NPROAPI-3', 'id': '8160', 'tc_external_id': '3', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8159', 'name': 'TESTCASE_B2'}],
'NPROAPI-3' : [{'full_tc_external_id': 'NPROAPI-3', 'id': '8160', 'tc_external_id': '3', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8159', 'name': 'TESTCASE_B2'}],
'8169' : [{'full_tc_external_id': 'NPROAPI-4', 'id': '8170', 'tc_external_id': '3', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8169', 'name': 'TESTCASE_B3'}],
'NPROAPI-4' : [{'full_tc_external_id': 'NPROAPI-4', 'id': '8170', 'tc_external_id': '3', 'version': '1',
'testsuite_id': 'deepFalse3', 'testcase_id': '8169', 'name': 'TESTCASE_B3'}] }
}


Expand Down Expand Up @@ -245,7 +258,14 @@ def _callServer(self, methodAPI, argsAPI=None):
elif methodAPI in ['getTestCaseIDByName']:
response = data[argsAPI['testcasename']]
elif methodAPI in ['getTestCase']:
response = data['%(testcaseid)s-%(version)s' % argsAPI]
datakey = argsAPI.get('testcaseid')
if datakey:
datakey = str(datakey)
else:
datakey = argsAPI.get('testcaseexternalid', '')
if argsAPI.has_key('version'):
datakey += '-%(version)s' % argsAPI
response = data[datakey]
elif methodAPI in ['getFullPath']:
response = data[argsAPI['nodeid']]
elif methodAPI in ['getTestProjectByName']:
Expand Down Expand Up @@ -472,6 +492,33 @@ def test_whatArgs_getTestCasesForTestSuite(self):
argsDescription = self.api.whatArgs('getTestCasesForTestSuite')
self.assertIn('getkeywords=<getkeywords>', argsDescription)

def test_listKeywordsForTC_FullExternalId(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTC('NPROAPI-2')
self.assertEqual(['KeyWord01', 'KeyWord03'], response)

def test_listKeywordsForTC_InternalId_Int(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTC(8144)
self.assertEqual(['KeyWord01', 'KeyWord03'], response)

def test_listKeywordsForTC_InternalId_String(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTC('8144')
self.assertEqual(['KeyWord01', 'KeyWord03'], response)

def test_listKeywordsForTC_One(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTC('NPROAPI-3')
self.assertEqual(['KeyWord02'], response)

def test_listKeywordsForTC_None(self):
self.api.loadScenario(SCENARIO_KEYWORDS)
response = self.api.listKeywordsForTC('NPROAPI-4')
self.assertEqual([], response)





if __name__ == "__main__":
Expand Down

0 comments on commit dffd8f8

Please sign in to comment.