Skip to content

Commit a24177a

Browse files
author
Luiko Czub
committed
handling of TestLink response error code added lczub#7
1 parent 46d65c0 commit a24177a

8 files changed

+264
-212
lines changed

example/TestLinkExample.py

+102-70
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#! /usr/bin/python
22
# -*- coding: UTF-8 -*-
3+
from compiler.pycodegen import TRY_FINALLY
4+
from symbol import except_clause
35

46
# Copyright 2011-2013 Olivier Renault, TestLink-API-Python-client developers
57
#
@@ -46,14 +48,15 @@
4648
|
4749
--- 5 automated test steps
4850
49-
Update 12. Oct. 2013, L. Czub
50-
Integrates v0.4.5 changes for optional arguments
51+
Update Oct. 2013, L. Czub
52+
Integrates v0.4.5 changes for optional arguments and response error handling
5153
The v0.4.0 method calls are still visible as comments (look for CHANGE v0.4.5)
5254
So this file helps to understand where existing own code needs adjustment.
5355
-
5456
used as behaviour is still
5557
"""
5658
from testlink import TestlinkAPIClient, TestLinkHelper
59+
from testlink.testlinkerrors import TLResponseError
5760
import sys
5861

5962
# precondition a)
@@ -77,8 +80,10 @@
7780
=> Create a new Project with the following structure:''')
7881
myTestLink = tl_helper.connect(TestlinkAPIClient)
7982

83+
projNr=len(myTestLink.getProjects())+1
8084

81-
NEWPROJECT="NEW_PROJECT_API"
85+
NEWPROJECT="NEW_PROJECT_API-%i" % projNr
86+
NEWPREFIX="NPROAPI%i" % projNr
8287
NEWTESTPLAN="TestPlan_API"
8388
NEWTESTSUITE_A="A - First Level"
8489
NEWTESTSUITE_B="B - First Level"
@@ -87,10 +92,24 @@
8792
NEWTESTCASE_B="TESTCASE_B"
8893
NEWBUILD="Build v0.4.5"
8994

90-
91-
if myTestLink.checkDevKey() != True:
92-
print "Error with the devKey."
93-
sys.exit(-1)
95+
# -- Start CHANGE v0.4.5 --
96+
# if myTestLink.checkDevKey() != True:
97+
# print "Error with the devKey."
98+
# sys.exit(-1)
99+
# example handling Response Error Codes
100+
# first check an invalid devKey and than the own one
101+
try:
102+
myTestLink.checkDevKey(devKey='007')
103+
except TLResponseError as tl_err:
104+
if tl_err.code == 2000:
105+
# expected invalid devKey Error
106+
# now check the own one - just call with default settings
107+
myTestLink.checkDevKey()
108+
else:
109+
# seems to be another response failure - we forward it
110+
raise
111+
# -- END CHANGE v0.4.5 --
112+
94113

95114
print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),)
96115
print ""
@@ -103,72 +122,86 @@
103122
# newProject = myTestLink.createTestProject(NEWPROJECT, "NPROAPI",
104123
# "notes=This is a Project created with the API", "active=1", "public=1",
105124
# "options=requirementsEnabled:0,testPriorityEnabled:1,automationEnabled:1,inventoryEnabled:0")
106-
newProject = myTestLink.createTestProject(NEWPROJECT, "NPROAPI",
125+
# isOk = newProject[0]['message']
126+
# if isOk=="Success!":
127+
# newProjectID = newProject[0]['id']
128+
# print "New Project '%s' - id: %s" % (NEWPROJECT,newProjectID)
129+
# else:
130+
# print "Error creating the project '%s': %s " % (NEWPROJECT,isOk)
131+
# sys.exit(-1)
132+
newProject = myTestLink.createTestProject(NEWPROJECT, NEWPREFIX,
107133
notes='This is a Project created with the API', active=1, public=1,
108134
options={'requirementsEnabled' : 0, 'testPriorityEnabled' : 1,
109135
'automationEnabled' : 1, 'inventoryEnabled' : 0})
136+
newProjectID = newProject[0]['id']
137+
print "New Project '%s' - id: %s" % (NEWPROJECT,newProjectID)
110138
# -- END CHANGE v0.4.5 --
111-
isOk = newProject[0]['message']
112-
if isOk=="Success!":
113-
newProjectID = newProject[0]['id']
114-
print "New Project '%s' - id: %s" % (NEWPROJECT,newProjectID)
115-
else:
116-
print "Error creating the project '%s': %s " % (NEWPROJECT,isOk)
117-
sys.exit(-1)
118139

119140
# Creates the test plan
120141
# -- Start CHANGE v0.4.5 --
121142
# newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT,
122143
# "notes=New TestPlan created with the API","active=1", "public=1")
144+
# isOk = newTestPlan[0]['message']
145+
# if isOk=="Success!":
146+
# newTestPlanID = newTestPlan[0]['id']
147+
# print "New Test Plan '%s' - id: %s" % (NEWTESTPLAN,newTestPlanID)
148+
# else:
149+
# print "Error creating the Test Plan '%s': %s " % (NEWTESTPLAN, isOk)
150+
# sys.exit(-1)
123151
newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT,
124152
notes='New TestPlan created with the API',active=1, public=1)
153+
newTestPlanID = newTestPlan[0]['id']
154+
print "New Test Plan '%s' - id: %s" % (NEWTESTPLAN,newTestPlanID)
125155
# -- END CHANGE v0.4.5 --
126-
isOk = newTestPlan[0]['message']
127-
if isOk=="Success!":
128-
newTestPlanID = newTestPlan[0]['id']
129-
print "New Test Plan '%s' - id: %s" % (NEWTESTPLAN,newTestPlanID)
130-
else:
131-
print "Error creating the Test Plan '%s': %s " % (NEWTESTPLAN, isOk)
132-
sys.exit(-1)
133156

134157
#Creates the test Suite A
135158
newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_A,
136159
"Details of the Test Suite A")
137-
isOk = newTestSuite[0]['message']
138-
if isOk=="ok":
139-
newTestSuiteID = newTestSuite[0]['id']
140-
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_A, newTestSuiteID)
141-
else:
142-
print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_A, isOk)
143-
sys.exit(-1)
160+
# -- Start CHANGE v0.4.5 --
161+
# isOk = newTestSuite[0]['message']
162+
# if isOk=="ok":
163+
# newTestSuiteID = newTestSuite[0]['id']
164+
# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_A, newTestSuiteID)
165+
# else:
166+
# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_A, isOk)
167+
# sys.exit(-1)
168+
newTestSuiteID = newTestSuite[0]['id']
169+
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_A, newTestSuiteID)
170+
# -- END CHANGE v0.4.5 --
144171

145172
FirstLevelID = newTestSuiteID
146173

147174
#Creates the test Suite B
148175
newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_B,
149176
"Details of the Test Suite B")
150-
isOk = newTestSuite[0]['message']
151-
if isOk=="ok":
152-
TestSuiteID_B = newTestSuite[0]['id']
153-
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_B, TestSuiteID_B)
154-
else:
155-
print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_B, isOk)
156-
sys.exit(-1)
177+
# -- Start CHANGE v0.4.5 --
178+
# isOk = newTestSuite[0]['message']
179+
# if isOk=="ok":
180+
# TestSuiteID_B = newTestSuite[0]['id']
181+
# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_B, TestSuiteID_B)
182+
# else:
183+
# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_B, isOk)
184+
# sys.exit(-1)
185+
TestSuiteID_B = newTestSuite[0]['id']
186+
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_B, TestSuiteID_B)
187+
# -- END CHANGE v0.4.5 --
157188

158189
#Creates the test Suite AA
159190
# -- Start CHANGE v0.4.5 --
160191
# newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_AA,
161192
# "Details of the Test Suite AA","parentid="+FirstLevelID)
193+
# isOk = newTestSuite[0]['message']
194+
# if isOk=="ok":
195+
# TestSuiteID_AA = newTestSuite[0]['id']
196+
# print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_AA, TestSuiteID_AA)
197+
# else:
198+
# print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_AA, isOk)
199+
# sys.exit(-1)
162200
newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_AA,
163201
"Details of the Test Suite AA",parentid=FirstLevelID)
202+
TestSuiteID_AA = newTestSuite[0]['id']
203+
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_AA, TestSuiteID_AA)
164204
# -- END CHANGE v0.4.5 --
165-
isOk = newTestSuite[0]['message']
166-
if isOk=="ok":
167-
TestSuiteID_AA = newTestSuite[0]['id']
168-
print "New Test Suite '%s' - id: %s" % (NEWTESTSUITE_AA, TestSuiteID_AA)
169-
else:
170-
print "Error creating the Test Suite '%s': %s " % (NEWTESTSUITE_AA, isOk)
171-
sys.exit(-1)
172205

173206
MANUAL = 1
174207
AUTOMATED = 2
@@ -184,17 +217,19 @@
184217
# newTestCase = myTestLink.createTestCase(NEWTESTCASE_AA, TestSuiteID_AA,
185218
# newProjectID, "admin", "This is the summary of the Test Case AA",
186219
# "preconditions=these are the preconditions")
220+
# isOk = newTestCase[0]['message']
221+
# if isOk=="Success!":
222+
# newTestCaseID_AA = newTestCase[0]['id']
223+
# print "New Test Case '%s' - id: %s" % (NEWTESTCASE_AA, newTestCaseID_AA)
224+
# else:
225+
# print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_AA, isOk)
226+
# sys.exit(-1)
187227
newTestCase = myTestLink.createTestCase(NEWTESTCASE_AA, TestSuiteID_AA,
188228
newProjectID, "admin", "This is the summary of the Test Case AA",
189-
preconditions='these are the preconditions')
229+
preconditions='these are the preconditions')
230+
newTestCaseID_AA = newTestCase[0]['id']
231+
print "New Test Case '%s' - id: %s" % (NEWTESTCASE_AA, newTestCaseID_AA)
190232
# -- END CHANGE v0.4.5 --
191-
isOk = newTestCase[0]['message']
192-
if isOk=="Success!":
193-
newTestCaseID_AA = newTestCase[0]['id']
194-
print "New Test Case '%s' - id: %s" % (NEWTESTCASE_AA, newTestCaseID_AA)
195-
else:
196-
print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_AA, isOk)
197-
sys.exit(-1)
198233

199234
#Creates the test case TC_B
200235
myTestLink.initStep("Step action 1", "Step result 1", AUTOMATED)
@@ -208,17 +243,19 @@
208243
# newProjectID, "admin", "This is the summary of the Test Case B",
209244
# "preconditions=these are the preconditions",
210245
# "executiontype=%i" % AUTOMATED)
246+
# isOk = newTestCase[0]['message']
247+
# if isOk=="Success!":
248+
# newTestCaseID_B = newTestCase[0]['id']
249+
# print "New Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID_B)
250+
# else:
251+
# print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_B, isOk)
252+
# sys.exit(-1)
211253
newTestCase = myTestLink.createTestCase(NEWTESTCASE_B, TestSuiteID_B,
212254
newProjectID, "admin", "This is the summary of the Test Case B",
213-
preconditions='these are the preconditions', executiontype=AUTOMATED)
255+
preconditions='these are the preconditions', executiontype=AUTOMATED)
256+
newTestCaseID_B = newTestCase[0]['id']
257+
print "New Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID_B)
214258
# -- END CHANGE v0.4.5 --
215-
isOk = newTestCase[0]['message']
216-
if isOk=="Success!":
217-
newTestCaseID_B = newTestCase[0]['id']
218-
print "New Test Case '%s' - id: %s" % (NEWTESTCASE_B, newTestCaseID_B)
219-
else:
220-
print "Error creating the Test Case '%s': %s " % (NEWTESTCASE_B, isOk)
221-
sys.exit(-1)
222259

223260
# -- New Examples with v0.4.5 --
224261

@@ -241,21 +278,16 @@
241278
# -- Create Build
242279
newBuild = myTestLink.createBuild(newTestPlanID, NEWBUILD, 'Notes for the Build')
243280
print newBuild
244-
isOk = newBuild[0]['message']
245-
if isOk=="Success!":
246-
newBuildID = newBuild[0]['id']
247-
print "New Build '%s' - id: %s" % (NEWBUILD, newBuildID)
248-
else:
249-
print "Error creating the Build '%s': %s " % (NEWBUILD, isOk)
250-
sys.exit(-1)
281+
newBuildID = newBuild[0]['id']
282+
print "New Build '%s' - id: %s" % (NEWBUILD, newBuildID)
251283

252284
# report Test Case Results
253-
# TC_AA failed
254-
newResult = myTestLink.reportTCResult(newTestPlanID, newTestCaseID_AA, NEWBUILD,
255-
'f', '')
285+
# TC_AA failed, build should be guessed, TC identified with external id
286+
newResult = myTestLink.reportTCResult(None, newTestPlanID, None, 'f', '', guess=True,
287+
testcaseexternalid=tc_aa_full_ext_id)
256288
print newResult
257289
# TC_B passed, explicit build and some notes , TC identified with internal id
258-
newResult = myTestLink.reportTCResult(newTestPlanID, newTestCaseID_B, NEWBUILD,
290+
newResult = myTestLink.reportTCResult(newTestCaseID_B, newTestPlanID, NEWBUILD,
259291
'p', 'first try')
260292
print newResult
261293

0 commit comments

Comments
 (0)