Skip to content

Commit 0a27e68

Browse files
author
Luiko Czub
committed
getTestCasesForTestSuite - new optional argument 'getkeywords' #24
1 parent 25a9610 commit 0a27e68

File tree

6 files changed

+173
-33
lines changed

6 files changed

+173
-33
lines changed

CHANGES.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,13 @@ Changes in TestLink-API-Python-client Source Distribution
44
TestLink-API-Python-client UNDER DEVELOP v0.4.9
55
-----------------------------------------------------------
66

7-
implement 1.9.10 api change - getTestCasesForTestSuite #23 - under construction
8-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7+
implement 1.9.10 api change - getTestCasesForTestSuite #23
8+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9+
10+
TestlinkAPIGeneric and TestlinkAPIClient api method getTestCasesForTestSuite()
11+
accepts now following additional optional arguments (usable with TL >= 1.9.10)
912

10-
- parameter keywords
13+
- parameter getkeywords
1114

1215
implement 1.9.10 api change - reportTCResult #24
1316
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

example/TestLinkExampleCustomFields.py

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,20 @@
2424
This example requires a special existing project with special custom fields
2525
assigned
2626
27-
a) run example TestLinkExampleGenericApi.py
28-
- this creates a project like PROJECT_API_GENERIC-7
27+
a) run example TestLinkExample.py
28+
- this creates a project like NEW_PROJECT_API-7
2929
if some additional project are created since running that example, adapt
3030
variable projNr in this script your are reading currently
3131
b) load custom field definitions customFields_ExampleDefs.xml
3232
TL - Desktop - System - Define Custom Fields - Import
33-
c) assign custom fields to project PROJECT_API_GENERIC-7
34-
TL - Test Project - Assign Custom Fields
33+
c) assign custom fields to project NEW_PROJECT_API-7
34+
TL - Desktop - Test Project - Assign Custom Fields
35+
d) load keyword definitions keywords_ExampleDefs.xml
36+
TL - Desktop - Test Project - Keyword Management
3537
3638
Script works with:
3739
38-
TestProject PROJECT_API_GENERIC-7
40+
TestProject NEW_PROJECT_API-7
3941
- TestSuite B - First Level
4042
- TestCase TESTCASE_B
4143
- TestPlan TestPlan_API_GENERIC A (Platform Small Bird)
@@ -51,9 +53,12 @@
5153
- requirement and requirement specifications
5254
- testplan - testcase link
5355
could be requested via api, these example does not work currently.
56+
57+
Script returns keywords from test case TESTCASE_B, if the user has assigned
58+
manually some values.
5459
5560
"""
56-
from testlink import TestlinkAPIGeneric, TestLinkHelper
61+
from testlink import TestlinkAPIClient, TestLinkHelper
5762
from testlink.testlinkerrors import TLResponseError
5863
import sys, os.path
5964

@@ -74,27 +79,27 @@
7479
# (new) http://YOURSERVER/testlink/lib/api/xmlrpc/v1/xmlrpc.php
7580
tl_helper = TestLinkHelper()
7681
tl_helper.setParamsFromArgs('''Shows how to use the TestLinkAPI for CustomFields.
77-
=> requires an existing project PROJECT_API_GENERIC-*''')
78-
myTestLink = tl_helper.connect(TestlinkAPIGeneric)
82+
=> requires an existing project NEW_PROJECT_API-*''')
83+
myTestLink = tl_helper.connect(TestlinkAPIClient)
7984

8085
#projNr=len(myTestLink.getProjects())+1
8186
projNr=len(myTestLink.getProjects())
8287

83-
NEWPROJECT="PROJECT_API_GENERIC-%i" % projNr
84-
NEWPREFIX="GPROAPI%i" % projNr
85-
NEWTESTPLAN_A="TestPlan_API_GENERIC A"
86-
NEWTESTPLAN_B="TestPlan_API_GENERIC B"
87-
NEWPLATFORM_A='Big Bird %i' % projNr
88-
NEWPLATFORM_B='Small Bird'
89-
NEWPLATFORM_C='Ugly Bird'
88+
NEWPROJECT="NEW_PROJECT_API-%i" % projNr
89+
NEWPREFIX="NPROAPI%i" % projNr
90+
NEWTESTPLAN_A="TestPlan_API A"
91+
# NEWTESTPLAN_B="TestPlan_API B"
92+
# NEWPLATFORM_A='Big Bird %i' % projNr
93+
NEWPLATFORM_B='Small Birds'
94+
# NEWPLATFORM_C='Ugly Bird'
9095
NEWTESTSUITE_A="A - First Level"
9196
NEWTESTSUITE_B="B - First Level"
9297
NEWTESTSUITE_AA="AA - Second Level"
93-
NEWTESTCASE_AA="TESTCASE_AA"
98+
# NEWTESTCASE_AA="TESTCASE_AA"
9499
NEWTESTCASE_B="TESTCASE_B"
95-
myApiVersion='%s v%s' % (myTestLink.__class__.__name__ , myTestLink.__version__)
96-
NEWBUILD_A='%s' % myApiVersion
97-
NEWBUILD_B='%s' % myApiVersion
100+
# myApiVersion='%s v%s' % (myTestLink.__class__.__name__ , myTestLink.__version__)
101+
# NEWBUILD_A='%s' % myApiVersion
102+
# NEWBUILD_B='%s' % myApiVersion
98103

99104
NEWATTACHMENT_PY= os.path.realpath(__file__)
100105
this_file_dirname=os.path.dirname(NEWATTACHMENT_PY)
@@ -123,6 +128,7 @@
123128
response = myTestLink.getBuildsForTestPlan(newTestPlanID_A)
124129
print "getBuildsForTestPlan", response
125130
newBuildID_A = response[0]['id']
131+
newBuildName_A = response[0]['name']
126132
# get information - TestSuite
127133
response = myTestLink.getTestSuitesForTestPlan(newTestPlanID_A)
128134
print "getTestSuitesForTestPlan", response
@@ -132,8 +138,9 @@
132138
newTestSuite = myTestLink.getTestSuiteByID(newTestSuiteID_B)
133139
print "getTestSuiteByID", newTestSuite
134140

135-
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B,
136-
deep=True, details='full', getkeywords=True)
141+
# list test cases with assigned keywords
142+
response = myTestLink.getTestCasesForTestSuite(newTestSuiteID_B, True,
143+
'full', getkeywords=True)
137144
print "getTestCasesForTestSuite", response
138145

139146
# get informationen - TestCase_B
@@ -147,16 +154,14 @@
147154

148155
# new execution result with custom field data
149156
# TC_B passed, explicit build and some notes , TC identified with internal id
150-
newResult = myTestLink.reportTCResult(newTestPlanID_A, 'p',
151-
buildid=newBuildID_A, testcaseid=newTestCaseID_B,
152-
platformname=NEWPLATFORM_B, notes="custom try",
157+
newResult = myTestLink.reportTCResult(newTestCaseID_B, newTestPlanID_A,
158+
newBuildName_A, 'p', "custom try", platformname=NEWPLATFORM_B,
153159
customfields={'cf_tc_ex_string' : 'a custom exec value set via api',
154160
'cf_tc_sd_listen' : 'ernie'})
155161
print "reportTCResult", newResult
156162

157163
# get execution results
158-
lastResult = myTestLink.getLastExecutionResult(
159-
newTestPlanID_A, testcaseid=newTestCaseID_B)[0]
164+
lastResult = myTestLink.getLastExecutionResult(newTestPlanID_A, newTestCaseID_B)[0]
160165
print "getLastExecutionResult", lastResult
161166

162167
# map of used ids
@@ -190,17 +195,17 @@
190195
#response = myTestLink._callServer('getTestCaseCustomFieldDesignValue', args)
191196
response = myTestLink.getTestCaseCustomFieldDesignValue(
192197
args['testcaseexternalid'], args['version'],
193-
args['testprojectid'], 'cf_tc_sd_string', details = 'full')
198+
args['testprojectid'], 'cf_tc_sd_string', 'full')
194199
print "getTestCaseCustomFieldDesignValue full", response
195200

196201
response = myTestLink.getTestCaseCustomFieldDesignValue(
197202
args['testcaseexternalid'], args['version'],
198-
args['testprojectid'], 'cf_tc_sd_string', details = 'value')
203+
args['testprojectid'], 'cf_tc_sd_string', 'value')
199204
print "getTestCaseCustomFieldDesignValue value", response
200205

201206
response = myTestLink.getTestCaseCustomFieldDesignValue(
202207
args['testcaseexternalid'], args['version'],
203-
args['testprojectid'], 'cf_tc_sd_list', details = 'simple')
208+
args['testprojectid'], 'cf_tc_sd_list', 'simple')
204209
print "getTestCaseCustomFieldDesignValue simple", response
205210

206211
# get CustomField Value - TestCase Testplan Design

example/keywords_ExampleDefs.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<keywords>
3+
<keyword name="KeyWord01">
4+
<notes><![CDATA[a key word]]></notes>
5+
</keyword>
6+
<keyword name="KeyWord02">
7+
<notes><![CDATA[another key word]]></notes>
8+
</keyword>
9+
<keyword name="KeyWord03">
10+
<notes><![CDATA[a third key word]]></notes>
11+
</keyword>
12+
</keywords>

src/testlink/testlinkapigeneric.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,13 +174,22 @@ def createTestProject(self):
174174

175175
@decoMakerApiCallReplaceTLResponseError()
176176
@decoApiCallAddDevKey
177-
@decoMakerApiCallWithArgs(['testsuiteid'], ['deep', 'details'])
177+
@decoMakerApiCallWithArgs(['testsuiteid'], ['deep', 'details',
178+
'getkeywords'])
178179
def getTestCasesForTestSuite(self):
179180
""" List test suites within a test plan alphabetically
180181
181182
details - default is 'simple',
182183
use 'full' if you want to get summary,steps & expected_results
183184
or 'only_id', if you just need an ID list
185+
186+
deep - True/False - default is True
187+
if True, return also test case of child suites
188+
189+
getkeywords - True/False - default is False
190+
if True AND details='full', dictionary includes for each test
191+
case, which as assigned keywords, an additional key value pair
192+
'keywords'
184193
185194
returns an empty list, if no build is assigned """
186195

test/utest-offline/testlinkapi_offline_test.py

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,68 @@
151151

152152
SCENARIO_STEPS = {'createTestCase' : ['noRealReponseData - ok for step tests']}
153153

154+
# scenario_keywords defines response with keywords
155+
SCENARIO_KEYWORDS = {'getTestCasesForTestSuite' : {
156+
'noTestCase' : [] ,
157+
158+
'deepTrue1' : [{'node_order': '0', 'is_open': '1',
159+
'keywords': {'3': {'keyword_id': '3', 'notes': 'a third key word', 'testcase_id': '8136', 'keyword': 'KeyWord03'}},
160+
'id': '8136', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '1', 'parent_id': '8135', 'version': '1',
161+
'estimated_exec_duration': '', 'updater_id': '2', 'status': '1', 'tsuite_name': 'AA - Second Level',
162+
'importance': '2', 'modification_ts': '2014-07-01 21:21:59', 'execution_type': '2',
163+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
164+
'node_table': 'testcases', 'tcversion_id': '8137', 'name': 'TESTCASE_AA',
165+
'summary': '<p>\n\tThis is the summary of the Test Case AA</p>\n',
166+
'steps': [{'step_number': '1', 'actions': 'Step action 1 - aa', 'execution_type': '1', 'active': '1', 'id': '8138', 'expected_results': 'Step result 1 - aa'},
167+
{'step_number': '2', 'actions': 'Step action 2 - aa', 'execution_type': '1', 'active': '1', 'id': '8139', 'expected_results': 'Step result 2 - aa'},
168+
{'step_number': '3', 'actions': 'Step action 3 - aa', 'execution_type': '1', 'active': '1', 'id': '8140', 'expected_results': 'Step result 3 - aa'},
169+
{'step_number': '4', 'actions': 'Step action 4 - aa', 'execution_type': '1', 'active': '1', 'id': '8141', 'expected_results': 'Step result 4 - aa'},
170+
{'step_number': '5', 'actions': 'Step action 5 - aa', 'execution_type': '1', 'active': '1', 'id': '8142', 'expected_results': 'Step result 5 - aa'}],
171+
'author_id': '1', 'external_id': 'GPROAPI10-1'}],
172+
173+
'deepFalse3' : [{'node_order': '0', 'is_open': '1',
174+
'keywords': {'1': {'keyword_id': '1', 'notes': 'a key word', 'testcase_id': '8144', 'keyword': 'KeyWord01'},
175+
'3': {'keyword_id': '3', 'notes': 'a third key word', 'testcase_id': '8144', 'keyword': 'KeyWord03'}},
176+
'id': '8144', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '2', 'parent_id': '8134', 'version': '1',
177+
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
178+
'importance': '3', 'modification_ts': '2014-06-30 20:45:40', 'execution_type': '1',
179+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-06-28 22:06:17',
180+
'node_table': 'testcases', 'tcversion_id': '8145', 'name': 'TESTCASE_B',
181+
'summary': '<p>\n\tThis is the summary of the Test Case B</p>\n',
182+
'steps': [{'step_number': '1', 'actions': 'Step action 1 -b ', 'execution_type': '2', 'active': '1', 'id': '8151', 'expected_results': 'Step result 1 - b'},
183+
{'step_number': '2', 'actions': 'Step action 2 -b ', 'execution_type': '2', 'active': '1', 'id': '8152', 'expected_results': 'Step result 2 - b'},
184+
{'step_number': '3', 'actions': 'action 3 createTestCaseSteps.update', 'execution_type': '2', 'active': '1', 'id': '8153', 'expected_results': 'update - cause step 3 already exist'},
185+
{'step_number': '4', 'actions': 'Step action 4 -b ', 'execution_type': '2', 'active': '1', 'id': '8154', 'expected_results': 'Step result 4 - b'},
186+
{'step_number': '5', 'actions': 'Step action 5 -b changed by updateTestCase', 'execution_type': '2', 'active': '1', 'id': '8155', 'expected_results': 'Step result 5 - b changed'},
187+
{'step_number': '6', 'actions': 'Step action 6 -b added by updateTestCase', 'execution_type': '2', 'active': '1', 'id': '8156', 'expected_results': 'Step result 6 - b added'},
188+
{'step_number': '7', 'actions': 'action 7 createTestCaseSteps.create', 'execution_type': '2', 'active': '1', 'id': '8157', 'expected_results': 'create - cause step 7 not yet exist'},
189+
{'step_number': '8', 'actions': 'action 8 createTestCaseSteps.update', 'execution_type': '2', 'active': '1', 'id': '8158', 'expected_results': 'create - cause step 8 not yet exist'}],
190+
'author_id': '1'},
191+
{'node_order': '1', 'is_open': '1',
192+
'keywords': {'2': {'keyword_id': '2', 'notes': 'another key word', 'testcase_id': '8159', 'keyword': 'KeyWord02'}},
193+
'id': '8159', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '3', 'parent_id': '8134', 'version': '1',
194+
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
195+
'importance': '3', 'modification_ts': '2014-07-02 21:03:02', 'execution_type': '1',
196+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-07-02 20:53:45',
197+
'node_table': 'testcases', 'tcversion_id': '8160', 'name': 'TESTCASE_B2',
198+
'summary': '<p>\n\tThis is the summary of the Test Case B2</p>\n',
199+
'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'},
200+
{'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'}],
201+
'author_id': '2'},
202+
{'node_order': '2', 'is_open': '1',
203+
'id': '8169', 'node_type_id': '3', 'layout': '1', 'tc_external_id': '4', 'parent_id': '8134', 'version': '1',
204+
'details': '<p>\n\tDetails of the Test Suite B</p>\n', 'estimated_exec_duration': '3.00', 'updater_id': '2', 'status': '1',
205+
'importance': '3', 'modification_ts': '2014-07-02 21:02:23', 'execution_type': '1',
206+
'preconditions': '<p>\n\tthese are the preconditions</p>\n', 'active': '1', 'creation_ts': '2014-07-02 20:55:46',
207+
'node_table': 'testcases', 'tcversion_id': '8170', 'name': 'TESTCASE_B3',
208+
'summary': '<p>\n\tThis is the summary of the Test Case B3</p>\n',
209+
'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'},
210+
{'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'}]
212+
}
213+
}
214+
215+
154216
class DummyAPIClient(TestlinkAPIClient):
155217
""" Dummy for Simulation TestLinkAPICLient.
156218
Overrides _callServer() Method to return test scenarios
@@ -397,6 +459,19 @@ def test_reportTCResult_user(self):
397459
def test_whatArgs_reportTCResult(self):
398460
argsDescription = self.api.whatArgs('reportTCResult')
399461
self.assertIn('user=<user>', argsDescription)
462+
463+
def test_getTestCasesForTestSuite_keyWords(self):
464+
self.api.loadScenario(SCENARIO_KEYWORDS)
465+
response = self.api.getTestCasesForTestSuite('deepFalse3', False,
466+
'full', getkeywords=True)
467+
self.assertIn('keywords', response[0])
468+
self.assertNotIn('keywords', response[2])
469+
self.assertEqual(self.api.devKey, self.api.callArgs['devKey'])
470+
471+
def test_whatArgs_getTestCasesForTestSuite(self):
472+
argsDescription = self.api.whatArgs('getTestCasesForTestSuite')
473+
self.assertIn('getkeywords=<getkeywords>', argsDescription)
474+
400475

401476

402477
if __name__ == "__main__":

0 commit comments

Comments
 (0)