Skip to content

Commit f2c4a6e

Browse files
author
Gauvain Pocentek
committed
Basic test for GitlabList
1 parent 15511bf commit f2c4a6e

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

gitlab/tests/test_gitlab.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,52 @@ def resp_cont(url, request):
171171
self.assertEqual(resp.status_code, 404)
172172

173173

174+
class TestGitlabList(unittest.TestCase):
175+
def setUp(self):
176+
self.gl = Gitlab("http://localhost", private_token="private_token",
177+
api_version=4)
178+
179+
def test_build_list(self):
180+
@urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests",
181+
method="get")
182+
def resp_1(url, request):
183+
headers = {'content-type': 'application/json',
184+
'X-Page': 1,
185+
'X-Next-Page': 2,
186+
'X-Per-Page': 1,
187+
'X-Total-Pages': 2,
188+
'X-Total': 2,
189+
'Link': (
190+
'<http://localhost/api/v4/tests?per_page=1&page=2>;'
191+
' rel="next"')}
192+
content = '[{"a": "b"}]'
193+
return response(200, content, headers, None, 5, request)
194+
195+
@urlmatch(scheme='http', netloc="localhost", path="/api/v4/tests",
196+
method='get', query=r'.*page=2')
197+
def resp_2(url, request):
198+
headers = {'content-type': 'application/json',
199+
'X-Page': 2,
200+
'X-Next-Page': 2,
201+
'X-Per-Page': 1,
202+
'X-Total-Pages': 2,
203+
'X-Total': 2}
204+
content = '[{"c": "d"}]'
205+
return response(200, content, headers, None, 5, request)
206+
207+
with HTTMock(resp_1):
208+
obj = self.gl.http_list('/tests')
209+
self.assertEqual(len(obj), 2)
210+
self.assertEqual(obj._next_url,
211+
'http://localhost/api/v4/tests?per_page=1&page=2')
212+
213+
with HTTMock(resp_2):
214+
l = list(obj)
215+
self.assertEqual(len(l), 2)
216+
self.assertEqual(l[0]['a'], 'b')
217+
self.assertEqual(l[1]['c'], 'd')
218+
219+
174220
class TestGitlabHttpMethods(unittest.TestCase):
175221
def setUp(self):
176222
self.gl = Gitlab("http://localhost", private_token="private_token",
@@ -260,7 +306,7 @@ def test_list_request(self):
260306
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/projects",
261307
method="get")
262308
def resp_cont(url, request):
263-
headers = {'content-type': 'application/json', 'X-Total-Pages': 1}
309+
headers = {'content-type': 'application/json', 'X-Total': 1}
264310
content = '[{"name": "project1"}]'
265311
return response(200, content, headers, None, 5, request)
266312

0 commit comments

Comments
 (0)