|
1 | 1 | #! /usr/bin/python
|
2 | 2 | # -*- coding: UTF-8 -*-
|
| 3 | +from compiler.pycodegen import TRY_FINALLY |
| 4 | +from symbol import except_clause |
3 | 5 |
|
4 | 6 | # Copyright 2011-2013 Olivier Renault, TestLink-API-Python-client developers
|
5 | 7 | #
|
|
46 | 48 | |
|
47 | 49 | --- 5 automated test steps
|
48 | 50 |
|
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 |
51 | 53 | The v0.4.0 method calls are still visible as comments (look for CHANGE v0.4.5)
|
52 | 54 | So this file helps to understand where existing own code needs adjustment.
|
53 | 55 | -
|
54 | 56 | used as behaviour is still
|
55 | 57 | """
|
56 | 58 | from testlink import TestlinkAPIClient, TestLinkHelper
|
| 59 | +from testlink.testlinkerrors import TLResponseError |
57 | 60 | import sys
|
58 | 61 |
|
59 | 62 | # precondition a)
|
|
77 | 80 | => Create a new Project with the following structure:''')
|
78 | 81 | myTestLink = tl_helper.connect(TestlinkAPIClient)
|
79 | 82 |
|
| 83 | +projNr=len(myTestLink.getProjects())+1 |
80 | 84 |
|
81 |
| -NEWPROJECT="NEW_PROJECT_API" |
| 85 | +NEWPROJECT="NEW_PROJECT_API-%i" % projNr |
| 86 | +NEWPREFIX="NPROAPI%i" % projNr |
82 | 87 | NEWTESTPLAN="TestPlan_API"
|
83 | 88 | NEWTESTSUITE_A="A - First Level"
|
84 | 89 | NEWTESTSUITE_B="B - First Level"
|
|
87 | 92 | NEWTESTCASE_B="TESTCASE_B"
|
88 | 93 | NEWBUILD="Build v0.4.5"
|
89 | 94 |
|
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 | + |
94 | 113 |
|
95 | 114 | print "Number of Projects in TestLink: %s " % (myTestLink.countProjects(),)
|
96 | 115 | print ""
|
|
103 | 122 | # newProject = myTestLink.createTestProject(NEWPROJECT, "NPROAPI",
|
104 | 123 | # "notes=This is a Project created with the API", "active=1", "public=1",
|
105 | 124 | # "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, |
107 | 133 | notes='This is a Project created with the API', active=1, public=1,
|
108 | 134 | options={'requirementsEnabled' : 0, 'testPriorityEnabled' : 1,
|
109 | 135 | 'automationEnabled' : 1, 'inventoryEnabled' : 0})
|
| 136 | +newProjectID = newProject[0]['id'] |
| 137 | +print "New Project '%s' - id: %s" % (NEWPROJECT,newProjectID) |
110 | 138 | # -- 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) |
118 | 139 |
|
119 | 140 | # Creates the test plan
|
120 | 141 | # -- Start CHANGE v0.4.5 --
|
121 | 142 | # newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT,
|
122 | 143 | # "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) |
123 | 151 | newTestPlan = myTestLink.createTestPlan(NEWTESTPLAN, NEWPROJECT,
|
124 | 152 | 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) |
125 | 155 | # -- 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) |
133 | 156 |
|
134 | 157 | #Creates the test Suite A
|
135 | 158 | newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_A,
|
136 | 159 | "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 -- |
144 | 171 |
|
145 | 172 | FirstLevelID = newTestSuiteID
|
146 | 173 |
|
147 | 174 | #Creates the test Suite B
|
148 | 175 | newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_B,
|
149 | 176 | "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 -- |
157 | 188 |
|
158 | 189 | #Creates the test Suite AA
|
159 | 190 | # -- Start CHANGE v0.4.5 --
|
160 | 191 | # newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_AA,
|
161 | 192 | # "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) |
162 | 200 | newTestSuite = myTestLink.createTestSuite(newProjectID, NEWTESTSUITE_AA,
|
163 | 201 | "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) |
164 | 204 | # -- 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) |
172 | 205 |
|
173 | 206 | MANUAL = 1
|
174 | 207 | AUTOMATED = 2
|
|
184 | 217 | # newTestCase = myTestLink.createTestCase(NEWTESTCASE_AA, TestSuiteID_AA,
|
185 | 218 | # newProjectID, "admin", "This is the summary of the Test Case AA",
|
186 | 219 | # "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) |
187 | 227 | newTestCase = myTestLink.createTestCase(NEWTESTCASE_AA, TestSuiteID_AA,
|
188 | 228 | 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) |
190 | 232 | # -- 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) |
198 | 233 |
|
199 | 234 | #Creates the test case TC_B
|
200 | 235 | myTestLink.initStep("Step action 1", "Step result 1", AUTOMATED)
|
|
208 | 243 | # newProjectID, "admin", "This is the summary of the Test Case B",
|
209 | 244 | # "preconditions=these are the preconditions",
|
210 | 245 | # "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) |
211 | 253 | newTestCase = myTestLink.createTestCase(NEWTESTCASE_B, TestSuiteID_B,
|
212 | 254 | 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) |
214 | 258 | # -- 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) |
222 | 259 |
|
223 | 260 | # -- New Examples with v0.4.5 --
|
224 | 261 |
|
|
241 | 278 | # -- Create Build
|
242 | 279 | newBuild = myTestLink.createBuild(newTestPlanID, NEWBUILD, 'Notes for the Build')
|
243 | 280 | 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) |
251 | 283 |
|
252 | 284 | # 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) |
256 | 288 | print newResult
|
257 | 289 | # 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, |
259 | 291 | 'p', 'first try')
|
260 | 292 | print newResult
|
261 | 293 |
|
|
0 commit comments