Skip to content

Commit 3b90d09

Browse files
committed
test: add pytest test dependency and remove sync TestGitlabList
1 parent fb90a89 commit 3b90d09

File tree

3 files changed

+3
-84
lines changed

3 files changed

+3
-84
lines changed

gitlab/tests/test_async_gitlab.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import pytest
22
import respx
3-
from httpx import status_codes
43
from httpx.status_codes import StatusCode
54

65
from gitlab import Gitlab, GitlabList

gitlab/tests/test_gitlab.py

Lines changed: 2 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,21 @@
1616
# You should have received a copy of the GNU Lesser General Public License
1717
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1818

19+
import json
1920
import os
2021
import pickle
2122
import tempfile
22-
import json
2323
import unittest
2424

25+
import requests
2526
from httmock import HTTMock # noqa
2627
from httmock import response # noqa
2728
from httmock import urlmatch # noqa
28-
import requests
2929

3030
import gitlab
3131
from gitlab import * # noqa
3232
from gitlab.v4.objects import * # noqa
3333

34-
3534
valid_config = b"""[global]
3635
default = one
3736
ssl_verify = true
@@ -58,86 +57,6 @@ def test_dict(self):
5857
self.assertEqual(expected, gitlab._sanitize(source))
5958

6059

61-
class TestGitlabList(unittest.TestCase):
62-
def setUp(self):
63-
self.gl = Gitlab(
64-
"http://localhost", private_token="private_token", api_version=4
65-
)
66-
67-
def test_build_list(self):
68-
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="get")
69-
def resp_1(url, request):
70-
headers = {
71-
"content-type": "application/json",
72-
"X-Page": 1,
73-
"X-Next-Page": 2,
74-
"X-Per-Page": 1,
75-
"X-Total-Pages": 2,
76-
"X-Total": 2,
77-
"Link": (
78-
"<http://localhost/api/v4/tests?per_page=1&page=2>;" ' rel="next"'
79-
),
80-
}
81-
content = '[{"a": "b"}]'
82-
return response(200, content, headers, None, 5, request)
83-
84-
@urlmatch(
85-
scheme="http",
86-
netloc="localhost",
87-
path="/api/v4/tests",
88-
method="get",
89-
query=r".*page=2",
90-
)
91-
def resp_2(url, request):
92-
headers = {
93-
"content-type": "application/json",
94-
"X-Page": 2,
95-
"X-Next-Page": 2,
96-
"X-Per-Page": 1,
97-
"X-Total-Pages": 2,
98-
"X-Total": 2,
99-
}
100-
content = '[{"c": "d"}]'
101-
return response(200, content, headers, None, 5, request)
102-
103-
with HTTMock(resp_1):
104-
obj = self.gl.http_list("/tests", as_list=False)
105-
self.assertEqual(len(obj), 2)
106-
self.assertEqual(
107-
obj._next_url, "http://localhost/api/v4/tests?per_page=1&page=2"
108-
)
109-
self.assertEqual(obj.current_page, 1)
110-
self.assertEqual(obj.prev_page, None)
111-
self.assertEqual(obj.next_page, 2)
112-
self.assertEqual(obj.per_page, 1)
113-
self.assertEqual(obj.total_pages, 2)
114-
self.assertEqual(obj.total, 2)
115-
116-
with HTTMock(resp_2):
117-
l = list(obj)
118-
self.assertEqual(len(l), 2)
119-
self.assertEqual(l[0]["a"], "b")
120-
self.assertEqual(l[1]["c"], "d")
121-
122-
def test_all_omitted_when_as_list(self):
123-
@urlmatch(scheme="http", netloc="localhost", path="/api/v4/tests", method="get")
124-
def resp(url, request):
125-
headers = {
126-
"content-type": "application/json",
127-
"X-Page": 2,
128-
"X-Next-Page": 2,
129-
"X-Per-Page": 1,
130-
"X-Total-Pages": 2,
131-
"X-Total": 2,
132-
}
133-
content = '[{"c": "d"}]'
134-
return response(200, content, headers, None, 5, request)
135-
136-
with HTTMock(resp):
137-
result = self.gl.http_list("/tests", as_list=False, all=True)
138-
self.assertIsInstance(result, GitlabList)
139-
140-
14160
class TestGitlabHttpMethods(unittest.TestCase):
14261
def setUp(self):
14362
self.gl = Gitlab(

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ sphinx>=1.3
99
sphinx_rtd_theme
1010
requests>=2.22.0
1111
respx>=0.10.0,<0.11
12+
pytest

0 commit comments

Comments
 (0)