|
26 | 26 | fromhttmockimportHTTMock# noqa
|
27 | 27 | fromhttmockimportresponse# noqa
|
28 | 28 | fromhttmockimporturlmatch# noqa
|
| 29 | +importsix |
29 | 30 |
|
30 | 31 | importgitlab
|
31 | 32 | fromgitlabimport*# noqa
|
@@ -243,6 +244,75 @@ def resp_two(url, request):
|
243 | 244 | self.assertEqual(data[0].ref,"b")
|
244 | 245 | self.assertEqual(len(data),2)
|
245 | 246 |
|
| 247 | +deftest_list_recursion_limit_caught(self): |
| 248 | +@urlmatch(scheme="http",netloc="localhost", |
| 249 | +path='/api/v3/projects/1/repository/branches',method="get") |
| 250 | +defresp_one(url,request): |
| 251 | +"""First request: |
| 252 | +
|
| 253 | + http://localhost/api/v3/projects/1/repository/branches?per_page=1 |
| 254 | + """ |
| 255 | +headers= { |
| 256 | +'content-type':'application/json', |
| 257 | +'link':'<http://localhost/api/v3/projects/1/repository/branc' |
| 258 | +'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' |
| 259 | +'/projects/1/repository/branches?page=2&per_page=0>; rel="las' |
| 260 | +'t", <http://localhost/api/v3/projects/1/repository/branches?' |
| 261 | +'page=1&per_page=0>; rel="first"' |
| 262 | + } |
| 263 | +content= ('[{"branch_name": "otherbranch", ' |
| 264 | +'"project_id": 1, "ref": "b"}]').encode("utf-8") |
| 265 | +resp=response(200,content,headers,None,5,request) |
| 266 | +returnresp |
| 267 | + |
| 268 | +@urlmatch(scheme="http",netloc="localhost", |
| 269 | +path='/api/v3/projects/1/repository/branches',method="get", |
| 270 | +query=r'.*page=2.*') |
| 271 | +defresp_two(url,request): |
| 272 | +# Mock a runtime error |
| 273 | +raiseRuntimeError("maximum recursion depth exceeded") |
| 274 | + |
| 275 | +withHTTMock(resp_two,resp_one): |
| 276 | +data=self.gl.list(ProjectBranch,project_id=1,per_page=1, |
| 277 | +safe_all=True) |
| 278 | +self.assertEqual(data[0].branch_name,"otherbranch") |
| 279 | +self.assertEqual(data[0].project_id,1) |
| 280 | +self.assertEqual(data[0].ref,"b") |
| 281 | +self.assertEqual(len(data),1) |
| 282 | + |
| 283 | +deftest_list_recursion_limit_not_caught(self): |
| 284 | +@urlmatch(scheme="http",netloc="localhost", |
| 285 | +path='/api/v3/projects/1/repository/branches',method="get") |
| 286 | +defresp_one(url,request): |
| 287 | +"""First request: |
| 288 | +
|
| 289 | + http://localhost/api/v3/projects/1/repository/branches?per_page=1 |
| 290 | + """ |
| 291 | +headers= { |
| 292 | +'content-type':'application/json', |
| 293 | +'link':'<http://localhost/api/v3/projects/1/repository/branc' |
| 294 | +'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' |
| 295 | +'/projects/1/repository/branches?page=2&per_page=0>; rel="las' |
| 296 | +'t", <http://localhost/api/v3/projects/1/repository/branches?' |
| 297 | +'page=1&per_page=0>; rel="first"' |
| 298 | + } |
| 299 | +content= ('[{"branch_name": "otherbranch", ' |
| 300 | +'"project_id": 1, "ref": "b"}]').encode("utf-8") |
| 301 | +resp=response(200,content,headers,None,5,request) |
| 302 | +returnresp |
| 303 | + |
| 304 | +@urlmatch(scheme="http",netloc="localhost", |
| 305 | +path='/api/v3/projects/1/repository/branches',method="get", |
| 306 | +query=r'.*page=2.*') |
| 307 | +defresp_two(url,request): |
| 308 | +# Mock a runtime error |
| 309 | +raiseRuntimeError("maximum recursion depth exceeded") |
| 310 | + |
| 311 | +withHTTMock(resp_two,resp_one): |
| 312 | +withsix.assertRaisesRegex(self,GitlabError, |
| 313 | +"(maximum recursion depth exceeded)"): |
| 314 | +self.gl.list(ProjectBranch,project_id=1,per_page=1,all=True) |
| 315 | + |
246 | 316 | deftest_list_401(self):
|
247 | 317 | @urlmatch(scheme="http",netloc="localhost",
|
248 | 318 | path="/api/v3/projects/1/repository/branches",method="get")
|
|