diff options
author | Johan Brandhorst <johan@cognitivelogic.com> | 2017-03-23 18:47:03 +0000 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-03-23 19:47:03 +0100 |
commit | 989f3b706d97045f4ea6af69fd11233e2f54adbf (patch) | |
tree | 70b97b110e8cd0d79d583b8d1354288d41ef66f0 /gitlab/tests | |
parent | 22bf12827387cb1719bacae6c0c745cd768eee6c (diff) | |
download | gitlab-989f3b706d97045f4ea6af69fd11233e2f54adbf.tar.gz |
Stop listing if recursion limit is hit (#234)
Diffstat (limited to 'gitlab/tests')
-rw-r--r-- | gitlab/tests/test_gitlab.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index 4adf07f..4670def 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -26,6 +26,7 @@ except ImportError: from httmock import HTTMock # noqa from httmock import response # noqa from httmock import urlmatch # noqa +import six import gitlab from gitlab import * # noqa @@ -243,6 +244,75 @@ class TestGitlabMethods(unittest.TestCase): self.assertEqual(data[0].ref, "b") self.assertEqual(len(data), 2) + def test_list_recursion_limit_caught(self): + @urlmatch(scheme="http", netloc="localhost", + path='/api/v3/projects/1/repository/branches', method="get") + def resp_one(url, request): + """First request: + + http://localhost/api/v3/projects/1/repository/branches?per_page=1 + """ + headers = { + 'content-type': 'application/json', + 'link': '<http://localhost/api/v3/projects/1/repository/branc' + 'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' + '/projects/1/repository/branches?page=2&per_page=0>; rel="las' + 't", <http://localhost/api/v3/projects/1/repository/branches?' + 'page=1&per_page=0>; rel="first"' + } + content = ('[{"branch_name": "otherbranch", ' + '"project_id": 1, "ref": "b"}]').encode("utf-8") + resp = response(200, content, headers, None, 5, request) + return resp + + @urlmatch(scheme="http", netloc="localhost", + path='/api/v3/projects/1/repository/branches', method="get", + query=r'.*page=2.*') + def resp_two(url, request): + # Mock a runtime error + raise RuntimeError("maximum recursion depth exceeded") + + with HTTMock(resp_two, resp_one): + data = self.gl.list(ProjectBranch, project_id=1, per_page=1, + safe_all=True) + self.assertEqual(data[0].branch_name, "otherbranch") + self.assertEqual(data[0].project_id, 1) + self.assertEqual(data[0].ref, "b") + self.assertEqual(len(data), 1) + + def test_list_recursion_limit_not_caught(self): + @urlmatch(scheme="http", netloc="localhost", + path='/api/v3/projects/1/repository/branches', method="get") + def resp_one(url, request): + """First request: + + http://localhost/api/v3/projects/1/repository/branches?per_page=1 + """ + headers = { + 'content-type': 'application/json', + 'link': '<http://localhost/api/v3/projects/1/repository/branc' + 'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' + '/projects/1/repository/branches?page=2&per_page=0>; rel="las' + 't", <http://localhost/api/v3/projects/1/repository/branches?' + 'page=1&per_page=0>; rel="first"' + } + content = ('[{"branch_name": "otherbranch", ' + '"project_id": 1, "ref": "b"}]').encode("utf-8") + resp = response(200, content, headers, None, 5, request) + return resp + + @urlmatch(scheme="http", netloc="localhost", + path='/api/v3/projects/1/repository/branches', method="get", + query=r'.*page=2.*') + def resp_two(url, request): + # Mock a runtime error + raise RuntimeError("maximum recursion depth exceeded") + + with HTTMock(resp_two, resp_one): + with six.assertRaisesRegex(self, GitlabError, + "(maximum recursion depth exceeded)"): + self.gl.list(ProjectBranch, project_id=1, per_page=1, all=True) + def test_list_401(self): @urlmatch(scheme="http", netloc="localhost", path="/api/v3/projects/1/repository/branches", method="get") |