8000 issue #63 add unit tests for 'next' link handling in list() · cdbennett/python-gitlab@719526d · GitHub
[go: up one dir, main page]

Skip to content

Commit 719526d

Browse files
committed
issue python-gitlab#63 add unit tests for 'next' link handling in list()
1 parent f9654cd commit 719526d

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

gitlab/tests/test_gitlab.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import unittest
2323
except ImportError:
2424
import unittest2 as unittest
25+
import json
2526

2627
from httmock import HTTMock # noqa
2728
from httmock import response # noqa
@@ -178,6 +179,56 @@ def resp_cont(url, request):
178179
self.assertEqual(data.project_id, 1)
179180
self.assertEqual(data.ref, "a")
180181

182+
def test_list_next_link(self):
183+
@urlmatch(scheme="http", netloc="localhost",
184+
path='/api/v3/projects/1/repository/branches', method="get",
185+
query=r'per_page=1')
186+
def resp_one(url, request):
187+
"""
188+
First request:
189+
http://localhost/api/v3/projects/1/repository/branches?per_page=1
190+
"""
191+
headers = {
192+
'content-type': 'application/json',
193+
'link': '<http://localhost/api/v3/projects/1/repository/branc' \
194+
'hes?page=2&per_page=0>; rel="next", <http://localhost/api/v3' \
195+
'/projects/1/repository/branches?page=2&per_page=0>; rel="las' \
196+
't", <http://localhost/api/v3/projects/1/repository/branches?' \
197+
'page=1&per_page=0>; rel="first"'
198+
}
199+
content = ('[{"branch_name": "otherbranch", '
200+
'"project_id": 1, "ref": "b"}]').encode("utf-8")
201+
resp = response(200, content, headers, None, 5, request)
202+
return resp
203+
204+
@urlmatch(scheme="http", netloc="localhost",
205+
path='/api/v3/projects/1/repository/branches', method="get",
206+
query=r'.*page=2.*')
207+
def resp_two(url, request):
208+
headers = {
209+
'content-type': 'application/json',
210+
'link': '<http://localhost/api/v3/projects/1/repository/branc' \
211+
'hes?page=1&per_page=0>; rel="prev", <http://localhost/api/v3' \
212+
'/projects/1/repository/branches?page=2&per_page=0>; rel="las' \
213+
't", <http://localhost/api/v3/projects/1/repository/branches?' \
214+
'page=1&per_page=0>; rel="first"'
215+
}
216+
content = ('[{"branch_name": "testbranch", '
217+
'"project_id": 1, "ref": "a"}]').encode("utf-8")
218+
resp = response(200, content, headers, None, 5, request)
219+
return resp
220+
221+
with HTTMock(resp_one, resp_two):
222+
data = self.gl.list(ProjectBranch, project_id=1,
223+
per_page=1)
224+
self.assertEqual(data[1].branch_name, "testbranch")
225+
self.assertEqual(data[1].project_id, 1)
226+
self.assertEqual(data[1].ref, "a")
227+
self.assertEqual(data[0].branch_name, "otherbranch")
228+
self.assertEqual(data[0].project_id, 1)
229+
self.assertEqual(data[0].ref, "b")
230+
self.assertEqual(len(data), 2)
231+
181232
def test_list_401(self):
182233
@urlmatch(scheme="http", netloc="localhost",
183234
path="/api/v3/projects/1/repository/branches", method="get")

0 commit comments

Comments
 (0)
0