Skip to content

Commit

Permalink
Basic test for GitlabList
Browse files Browse the repository at this point in the history
  • Loading branch information
Gauvain Pocentek committed Jun 5, 2017
1 parent 15511bf commit f2c4a6e
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion gitlab/tests/test_gitlab.py
Expand Up @@ -171,6 +171,52 @@ def resp_cont(url, request):
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",
Expand Down Expand Up @@ -260,7 +306,7 @@ def test_list_request(self):
@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)

Expand Down

0 comments on commit f2c4a6e

Please sign in to comment.