Skip to content

Commit 34666c7

Browse files
committed
test: fix all tests that are async
1 parent a14383b commit 34666c7

File tree

7 files changed

+72
-70
lines changed

7 files changed

+72
-70
lines changed

gitlab/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import gitlab.config
2727
from gitlab import exceptions as exc
2828
from gitlab import utils
29-
from gitlab.exceptions import on_http_error
29+
from gitlab.exceptions import GitlabHttpError, GitlabParsingError, on_http_error
3030
from gitlab.types import GitlabList
3131

3232
REDIRECT_MSG = (

gitlab/tests/objects/test_async_application.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import respx
55
from httpx.status_codes import StatusCode
66

7-
from gitlab import Gitlab
7+
from gitlab import AsyncGitlab
88

99

1010
class TestApplicationAppearance:
1111
@pytest.fixture
1212
def gl(self):
13-
return Gitlab(
13+
return AsyncGitlab(
1414
"http://localhost",
1515
private_token="private_token",
1616
ssl_verify=True,

gitlab/tests/objects/test_async_projects.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
import respx
33
from httpx.status_codes import StatusCode
44

5-
from gitlab import Gitlab
5+
from gitlab import AsyncGitlab
66

77

88
class TestProjectSnippets:
99
@pytest.fixture
1010
def gl(self):
11-
return Gitlab(
11+
return AsyncGitlab(
1212
"http://localhost",
1313
private_token="private_token",
1414
ssl_verify=True,
@@ -34,7 +34,7 @@ async def test_list_project_snippets(self, gl):
3434
status_code=StatusCode.OK,
3535
)
3636

37-
project = await gl.projects.get(1, lazy=True)
37+
project = gl.projects.get(1, lazy=True)
3838
snippets = await project.snippets.list()
3939
assert len(snippets) == 1
4040
assert snippets[0].title == title
@@ -57,7 +57,7 @@ async def test_get_project_snippet(self, gl):
5757
status_code=StatusCode.OK,
5858
)
5959

60-
project = await gl.projects.get(1, lazy=True)
60+
project = gl.projects.get(1, lazy=True)
6161
snippet = await project.snippets.get(1)
6262
assert snippet.title == title
6363
assert snippet.visibility == visibility
@@ -92,7 +92,7 @@ async def test_create_update_project_snippets(self, gl):
9292
status_code=StatusCode.OK,
9393
)
9494

95-
project = await gl.projects.get(1, lazy=True)
95+
project = gl.projects.get(1, lazy=True)
9696
snippet = await project.snippets.create(
9797
{
9898
"title": title,

gitlab/tests/test_async_gitlab.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
import respx
88
from httpx.status_codes import StatusCode
99

10-
from gitlab import Gitlab, GitlabList
10+
from gitlab import AsyncGitlab
1111
from gitlab import exceptions as exc
12+
from gitlab.types import GitlabList
1213
from gitlab.v4.objects import (
1314
CurrentUser,
1415
Group,
@@ -26,7 +27,9 @@
2627
class TestGitlabList:
2728
@pytest.fixture
2829
def gl(self):
29-
return Gitlab("http://localhost", private_token="private_token", api_version=4)
30+
return AsyncGitlab(
31+
"http://localhost", private_token="private_token", api_version=4
32+
)
3033

3134
@respx.mock
3235
@pytest.mark.asyncio
@@ -100,7 +103,9 @@ async def test_all_ommited_when_as_list(self, gl):
100103
class TestGitlabHttpMethods:
101104
@pytest.fixture
102105
def gl(self):
103-
return Gitlab("http://localhost", private_token="private_token", api_version=4)
106+
return AsyncGitlab(
107+
"http://localhost", private_token="private_token", api_version=4
108+
)
104109

105110
@respx.mock
106111
@pytest.mark.asyncio
@@ -263,7 +268,7 @@ async def test_delete_request_404(self, gl):
263268
class TestGitlab:
264269
@pytest.fixture
265270
def gl(self):
266-
return Gitlab(
271+
return AsyncGitlab(
267272
"http://localhost",
268273
private_token="private_token",
269274
ssl_verify=True,
@@ -517,7 +522,7 @@ async def test_deployment(self, gl):
517522
status_code=StatusCode.OK,
518523
)
519524

520-
project = await gl.projects.get(1, lazy=True)
525+
project = gl.projects.get(1, lazy=True)
521526
deployment = await project.deployments.create(
522527
{
523528
"environment": "Test",
@@ -558,7 +563,7 @@ async def test_user_activate_deactivate(self, gl):
558563
status_code=StatusCode.CREATED,
559564
)
560565

561-
user = await gl.users.get(1, lazy=True)
566+
user = gl.users.get(1, lazy=True)
562567
await user.activate()
563568
await user.deactivate()
564569

gitlab/tests/test_async_mixins.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import respx
33
from httpx.status_codes import StatusCode
44

5-
from gitlab import Gitlab
5+
from gitlab import AsyncGitlab
66
from gitlab.base import RESTObject, RESTObjectList
77
from gitlab.mixins import (
88
CreateMixin,
@@ -22,7 +22,9 @@
2222
class TestMixinMethods:
2323
@pytest.fixture
2424
def gl(self):
25-
return Gitlab("http://localhost", private_token="private_token", api_version=4)
25+
return AsyncGitlab(
26+
"http://localhost", private_token="private_token", api_version=4
27+
)
2628

2729
@respx.mock
2830
@pytest.mark.asyncio
@@ -123,11 +125,11 @@ class M(ListMixin, FakeManager):
123125
mgr = M(gl)
124126
obj_list = await mgr.list(path="/others", as_list=False)
125127
assert isinstance(obj_list, RESTObjectList)
126-
obj = await obj_list.next()
128+
obj = await obj_list.anext()
127129
assert obj.id == 42
128130
assert obj.foo == "bar"
129131
with pytest.raises(StopAsyncIteration):
130-
await obj_list.next()
132+
await obj_list.anext()
131133

132134
@respx.mock
133135
@pytest.mark.asyncio

gitlab/tests/test_gitlab.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import gitlab
3131
from gitlab import * # noqa
32+
from gitlab.client import _sanitize
3233
from gitlab.v4.objects import * # noqa
3334

3435
valid_config = b"""[global]
@@ -44,17 +45,17 @@
4445

4546
class TestSanitize(unittest.TestCase):
4647
def test_do_nothing(self):
47-
self.assertEqual(1, gitlab._sanitize(1))
48-
self.assertEqual(1.5, gitlab._sanitize(1.5))
49-
self.assertEqual("foo", gitlab._sanitize("foo"))
48+
self.assertEqual(1, _sanitize(1))
49+
self.assertEqual(1.5, _sanitize(1.5))
50+
self.assertEqual("foo", _sanitize("foo"))
5051

5152
def test_slash(self):
52-
self.assertEqual("foo%2Fbar", gitlab._sanitize("foo/bar"))
53+
self.assertEqual("foo%2Fbar", _sanitize("foo/bar"))
5354

5455
def test_dict(self):
5556
source = {"url": "foo/bar", "id": 1}
5657
expected = {"url": "foo%2Fbar", "id": 1}
57-
self.assertEqual(expected, gitlab._sanitize(source))
58+
self.assertEqual(expected, _sanitize(source))
5859

5960

6061
class TestGitlabHttpMethods(unittest.TestCase):

gitlab/types.py

Lines changed: 41 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
# You should have received a copy of the GNU Lesser General Public License
1616
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1717

18+
from .exceptions import GitlabParsingError
19+
1820

1921
class GitlabAttribute:
2022
def __init__(self, value=None):
@@ -56,53 +58,6 @@ def get_file_name(self, attr_name=None):
5658
return "%s.png" % attr_name if attr_name else "image.png"
5759

5860

59-
class GitlabList:
60-
"""Generator representing a list of remote objects.
61-
62-
The object handles the links returned by a query to the API, and will call
63-
the API again when needed.
64-
"""
65-
66-
@property
67-
def current_page(self):
68-
"""The current page number."""
69-
return int(self._current_page)
70-
71-
@property
72-
def prev_page(self):
73-
"""The next page number.
74-
75-
If None, the current page is the last.
76-
"""
77-
return int(self._prev_page) if self._prev_page else None
78-
79-
@property
80-
def next_page(self):
81-
"""The next page number.
82-
83-
If None, the current page is the last.
84-
"""
85-
return int(self._next_page) if self._next_page else None
86-
87-
@property
88-
def per_page(self):
89-
"""The number of items per page."""
90-
return int(self._per_page)
91-
92-
@property
93-
def total_pages(self):
94-
"""The total number of pages."""
95-
return int(self._total_pages)
96-
97-
@property
98-
def total(self):
99-
"""The total number of items."""
100-
return int(self._total)
101-
102-
def __len__(self):
103-
return int(self._total)
104-
105-
10661
class GitlabList:
10762
"""Generator representing a list of remote objects.
10863
@@ -162,6 +117,45 @@ def _query(self, url, query_data=None, **kwargs):
162117
result = self._gl.http_request("get", url, query_data=query_data, **kwargs)
163118
return self._process_query_result(result)
164119

120+
@property
121+
def current_page(self):
122+
"""The current page number."""
123+
return int(self._current_page)
124+
125+
@property
126+
def prev_page(self):
127+
"""The next page number.
128+
129+
If None, the current page is the last.
130+
"""
131+
return int(self._prev_page) if self._prev_page else None
132+
133+
@property
134+
def next_page(self):
135+
"""The next page number.
136+
137+
If None, the current page is the last.
138+
"""
139+
return int(self._next_page) if self._next_page else None
140+
141+
@property
142+
def per_page(self):
143+
"""The number of items per page."""
144+
return int(self._per_page)
145+
146+
@property
147+
def total_pages(self):
148+
"""The total number of pages."""
149+
return int(self._total_pages)
150+
151+
@property
152+
def total(self):
153+
"""The total number of items."""
154+
return int(self._total)
155+
156+
def __len__(self):
157+
return int(self._total)
158+
165159
def __iter__(self):
166160
return self
167161

0 commit comments

Comments
 (0)