diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2017-06-05 09:28:06 +0200 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2017-06-05 09:28:06 +0200 |
commit | f2c4a6e0e27eb5af795dd1a4281014502c1ff1e4 (patch) | |
tree | 8907c7b6734a0ded829cd6eee8b3f7d4265e3aa9 /gitlab/tests/test_gitlab.py | |
parent | 15511bfba32685b7c67ca8886626076cdf3561ab (diff) | |
download | gitlab-f2c4a6e0e27eb5af795dd1a4281014502c1ff1e4.tar.gz |
Basic test for GitlabList
Diffstat (limited to 'gitlab/tests/test_gitlab.py')
-rw-r--r-- | gitlab/tests/test_gitlab.py | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py index 1710fff..d642eaf 100644 --- a/gitlab/tests/test_gitlab.py +++ b/gitlab/tests/test_gitlab.py @@ -171,6 +171,52 @@ class TestGitlabRawMethods(unittest.TestCase): self.assertEqual(resp.status_code, 404) +class TestGitlabList(unittest.TestCase): + def setUp(self): + self.gl = Gitlab("http://localhost", private_token="private_token", + api_version=4) + + def test_build_list(self): + @urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests", + method="get") + def resp_1(url, request): + headers = {'content-type': 'application/json', + 'X-Page': 1, + 'X-Next-Page': 2, + 'X-Per-Page': 1, + 'X-Total-Pages': 2, + 'X-Total': 2, + 'Link': ( + '<http://localhost/api/v4/tests?per_page=1&page=2>;' + ' rel="next"')} + content = '[{"a": "b"}]' + return response(200, content, headers, None, 5, request) + + @urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests", + method='get', query=r'.*page=2') + def resp_2(url, request): + headers = {'content-type': 'application/json', + 'X-Page': 2, + 'X-Next-Page': 2, + 'X-Per-Page': 1, + 'X-Total-Pages': 2, + 'X-Total': 2} + content = '[{"c": "d"}]' + return response(200, content, headers, None, 5, request) + + with HTTMock(resp_1): + obj = self.gl.http_list('/tests') + self.assertEqual(len(obj), 2) + self.assertEqual(obj._next_url, + 'http://localhost/api/v4/tests?per_page=1&page=2') + + with HTTMock(resp_2): + l = list(obj) + self.assertEqual(len(l), 2) + self.assertEqual(l[0]['a'], 'b') + self.assertEqual(l[1]['c'], 'd') + + class TestGitlabHttpMethods(unittest.TestCase): def setUp(self): self.gl = Gitlab("http://localhost", private_token="private_token", @@ -260,7 +306,7 @@ class TestGitlabHttpMethods(unittest.TestCase): @urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects", method="get") def resp_cont(url, request): - headers = {'content-type': 'application/json', 'X-Total-Pages': 1} + headers = {'content-type': 'application/json', 'X-Total': 1} content = '[{"name": "project1"}]' return response(200, content, headers, None, 5, request) |