summaryrefslogtreecommitdiff
path: root/gitlab/tests/test_gitlab.py
diff options
context:
space:
mode:
authorJason Antman <jason@jasonantman.com>2015-08-05 18:38:43 -0400
committerJason Antman <jason@jasonantman.com>2015-08-05 18:38:43 -0400
commit719526dc8b0fb7d577f0a5ffa80d8f0ca31a95c6 (patch)
treefc0e64e56a311e0fb1a45e1eded90f43b0f16561 /gitlab/tests/test_gitlab.py
parentf9654cd1c0dca5b75a2ae78634b06feea7cc3b62 (diff)
downloadgitlab-719526dc8b0fb7d577f0a5ffa80d8f0ca31a95c6.tar.gz
issue #63 add unit tests for 'next' link handling in list()
Diffstat (limited to 'gitlab/tests/test_gitlab.py')
-rw-r--r--gitlab/tests/test_gitlab.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/gitlab/tests/test_gitlab.py b/gitlab/tests/test_gitlab.py
index f84bf86..5530843 100644
--- a/gitlab/tests/test_gitlab.py
+++ b/gitlab/tests/test_gitlab.py
@@ -22,6 +22,7 @@ try:
import unittest
except ImportError:
import unittest2 as unittest
+import json
from httmock import HTTMock # noqa
from httmock import response # noqa
@@ -178,6 +179,56 @@ class TestGitLabMethods(unittest.TestCase):
self.assertEqual(data.project_id, 1)
self.assertEqual(data.ref, "a")
+ def test_list_next_link(self):
+ @urlmatch(scheme="http", netloc="localhost",
+ path='/api/v3/projects/1/repository/branches', method="get",
+ query=r'per_page=1')
+ 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):
+ headers = {
+ 'content-type': 'application/json',
+ 'link': '<http://localhost/api/v3/projects/1/repository/branc' \
+ 'hes?page=1&per_page=0>; rel="prev", <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": "testbranch", '
+ '"project_id": 1, "ref": "a"}]').encode("utf-8")
+ resp = response(200, content, headers, None, 5, request)
+ return resp
+
+ with HTTMock(resp_one, resp_two):
+ data = self.gl.list(ProjectBranch, project_id=1,
+ per_page=1)
+ self.assertEqual(data[1].branch_name, "testbranch")
+ self.assertEqual(data[1].project_id, 1)
+ self.assertEqual(data[1].ref, "a")
+ self.assertEqual(data[0].branch_name, "otherbranch")
+ self.assertEqual(data[0].project_id, 1)
+ self.assertEqual(data[0].ref, "b")
+ self.assertEqual(len(data), 2)
+
def test_list_401(self):
@urlmatch(scheme="http", netloc="localhost",
path="/api/v3/projects/1/repository/branches", method="get")