Skip to content

Commit 6d0e2cb

Browse files
committed
test: test application is tested against async/sync interface
1 parent 0c4d320 commit 6d0e2cb

File tree

2 files changed

+54
-57
lines changed

2 files changed

+54
-57
lines changed

gitlab/tests/objects/test_async_application.py renamed to gitlab/tests/objects/test_application.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,9 @@
88

99

1010
class TestApplicationAppearance:
11-
@pytest.fixture
12-
def gl(self):
13-
return AsyncGitlab(
14-
"http://localhost",
15-
private_token="private_token",
16-
ssl_verify=True,
17-
api_version="4",
18-
)
19-
2011
@respx.mock
2112
@pytest.mark.asyncio
22-
async def test_get_update_appearance(self, gl):
13+
async def test_get_update_appearance(self, gl, gl_get_value, is_gl_sync):
2314
title = "GitLab Test Instance"
2415
new_title = "new-title"
2516
description = "gitlab-test.example.com"
@@ -60,18 +51,23 @@ async def test_get_update_appearance(self, gl):
6051
status_code=StatusCode.OK,
6152
)
6253

63-
appearance = await gl.appearance.get()
54+
appearance = gl.appearance.get()
55+
appearance = await gl_get_value(appearance)
56+
6457
assert appearance.title == title
6558
assert appearance.description == description
6659
appearance.title = new_title
6760
appearance.description = new_description
68-
await appearance.save()
61+
if is_gl_sync:
62+
appearance.save()
63+
else:
64+
await appearance.save()
6965
assert appearance.title == new_title
7066
assert appearance.description == new_description
7167

7268
@respx.mock
7369
@pytest.mark.asyncio
74-
async def test_update_appearance(self, gl):
70+
async def test_update_appearance(self, gl, is_gl_sync):
7571
new_title = "new-title"
7672
new_description = "new-description"
7773

@@ -93,4 +89,7 @@ async def test_update_appearance(self, gl):
9389
status_code=StatusCode.OK,
9490
)
9591

96-
await gl.appearance.update(title=new_title, description=new_description)
92+
if is_gl_sync:
93+
gl.appearance.update(title=new_title, description=new_description)
94+
else:
95+
await gl.appearance.update(title=new_title, description=new_description)

gitlab/v4/objects.py

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,7 +1182,7 @@ def merge_requests(self, **kwargs):
11821182
RESTObjectList: The list of merge requests
11831183
"""
11841184
path = "%s/%s/merge_requests" % (self.manager.path, self.get_id())
1185-
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
1185+
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
11861186
manager = GroupIssueManager(self.manager.gitlab, parent=self.manager._parent)
11871187
# FIXME(gpocentek): the computed manager path is not correct
11881188
return RESTObjectList(manager, GroupMergeRequest, data_list) # TODO: ???
@@ -1494,7 +1494,7 @@ def list(self, **kwargs):
14941494
else:
14951495
path = self._path
14961496

1497-
obj = self.gitlab.http_list(path, **data) # TODO: ???
1497+
obj = self.gitlab.http_list(path, **data) # TODO: ???
14981498
if isinstance(obj, list):
14991499
return [self._obj_cls(self, item) for item in obj]
15001500
else:
@@ -1567,10 +1567,10 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
15671567
str: The snippet content
15681568
"""
15691569
path = "/snippets/%s/raw" % self.get_id()
1570-
result = self.manager.gitlab.http_get(
1570+
result = self.manager.gitlab.http_get(
15711571
path, streamed=streamed, raw=True, **kwargs
15721572
)
1573-
return utils.response_content(result, streamed, action)
1573+
return utils.response_content(result, streamed, action)
15741574

15751575

15761576
class SnippetManager(CRUDMixin, RESTManager):
@@ -1736,7 +1736,7 @@ def unprotect(self, **kwargs):
17361736
"""
17371737
id = self.get_id().replace("/", "%2F")
17381738
path = "%s/%s/unprotect" % (self.manager.path, id)
1739-
server_data self.manager.gitlab.http_put(path, **kwargs)
1739+
server_data = self.manager.gitlab.http_put(path, **kwargs)
17401740
return self._change_protected(False, server_data)
17411741

17421742

@@ -1915,7 +1915,7 @@ def artifacts(self, streamed=False, action=None, chunk_size=1024, **kwargs):
19151915
str: The artifacts if `streamed` is False, None otherwise.
19161916
"""
19171917
path = "%s/%s/artifacts" % (self.manager.path, self.get_id())
1918-
result = self.manager.gitlab.http_get(
1918+
result = self.manager.gitlab.http_get(
19191919
path, streamed=streamed, raw=True, **kwargs
19201920
)
19211921
return utils.response_content(result, streamed, action)
@@ -1943,7 +1943,7 @@ def artifact(self, path, streamed=False, action=None, chunk_size=1024, **kwargs)
19431943
str: The artifacts if `streamed` is False, None otherwise.
19441944
"""
19451945
path = "%s/%s/artifacts/%s" % (self.manager.path, self.get_id(), path)
1946-
result = self.manager.gitlab.http_get(
1946+
result = self.manager.gitlab.http_get(
19471947
path, streamed=streamed, raw=True, **kwargs
19481948
)
19491949
return utils.response_content(result, streamed, action)
@@ -1970,10 +1970,10 @@ def trace(self, streamed=False, action=None, chunk_size=1024, **kwargs):
19701970
str: The trace
19711971
"""
19721972
path = "%s/%s/trace" % (self.manager.path, self.get_id())
1973-
result = self.manager.gitlab.http_get(
1973+
result = self.manager.gitlab.http_get(
19741974
path, streamed=streamed, raw=True, **kwargs
19751975
)
1976-
return utils.response_content(result, streamed, action)
1976+
return utils.response_content(result, streamed, action)
19771977

19781978

19791979
class ProjectJobManager(RetrieveMixin, RESTManager):
@@ -2423,7 +2423,7 @@ def create(self, data, **kwargs):
24232423
GitlabCreateError: If the server cannot perform the request
24242424
"""
24252425
self._check_missing_create_attrs(data)
2426-
server_data = self.gitlab.http_post(self.path, post_data=data, **kwargs)
2426+
server_data = self.gitlab.http_post(self.path, post_data=data, **kwargs)
24272427
source_issue = ProjectIssue(self._parent.manager, server_data["source_issue"])
24282428
target_issue = ProjectIssue(self._parent.manager, server_data["target_issue"])
24292429
return source_issue, target_issue # TODO: ???
@@ -2475,9 +2475,7 @@ def move(self, to_project_id, **kwargs):
24752475
"""
24762476
path = "%s/%s/move" % (self.manager.path, self.get_id())
24772477
data = {"to_project_id": to_project_id}
2478-
return self.manager.gitlab.http_post(
2479-
path, post_data=data, **kwargs
2480-
)
2478+
return self.manager.gitlab.http_post(path, post_data=data, **kwargs)
24812479

24822480
@cli.register_custom_action("ProjectIssue")
24832481
@exc.on_http_error(exc.GitlabGetError)
@@ -2939,7 +2937,7 @@ def commits(self, **kwargs):
29392937
"""
29402938

29412939
path = "%s/%s/commits" % (self.manager.path, self.get_id())
2942-
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
2940+
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
29432941
manager = ProjectCommitManager(self.manager.gitlab, parent=self.manager._parent)
29442942
return RESTObjectList(manager, ProjectCommit, data_list) # TODO: ???
29452943

@@ -2999,9 +2997,7 @@ def approve(self, sha=None, **kwargs):
29992997
if sha:
30002998
data["sha"] = sha
30012999

3002-
return self.manager.gitlab.http_post(
3003-
path, post_data=data, **kwargs
3004-
)
3000+
return self.manager.gitlab.http_post(path, post_data=data, **kwargs)
30053001

30063002
@cli.register_custom_action("ProjectMergeRequest")
30073003
@exc.on_http_error(exc.GitlabMRApprovalError)
@@ -3019,9 +3015,7 @@ def unapprove(self, **kwargs):
30193015
path = "%s/%s/unapprove" % (self.manager.path, self.get_id())
30203016
data = {}
30213017

3022-
return self.manager.gitlab.http_post(
3023-
path, post_data=data, **kwargs
3024-
)
3018+
return self.manager.gitlab.http_post(path, post_data=data, **kwargs)
30253019

30263020
@cli.register_custom_action("ProjectMergeRequest")
30273021
@exc.on_http_error(exc.GitlabMRRebaseError)
@@ -3163,7 +3157,7 @@ def issues(self, **kwargs):
31633157
"""
31643158

31653159
path = "%s/%s/issues" % (self.manager.path, self.get_id())
3166-
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
3160+
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
31673161
manager = ProjectIssueManager(self.manager.gitlab, parent=self.manager._parent)
31683162
# FIXME(gpocentek): the computed manager path is not correct
31693163
return RESTObjectList(manager, ProjectIssue, data_list) # TODO: ???
@@ -3189,7 +3183,7 @@ def merge_requests(self, **kwargs):
31893183
RESTObjectList: The list of merge requests
31903184
"""
31913185
path = "%s/%s/merge_requests" % (self.manager.path, self.get_id())
3192-
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
3186+
data_list = self.manager.gitlab.http_list(path, as_list=False, **kwargs)
31933187
manager = ProjectMergeRequestManager(
31943188
self.manager.gitlab, parent=self.manager._parent
31953189
)
@@ -3455,10 +3449,10 @@ def raw(
34553449
file_path = file_path.replace("/", "%2F").replace(".", "%2E")
34563450
path = "%s/%s/raw" % (self.path, file_path)
34573451
query_data = {"ref": ref}
3458-
result = self.gitlab.http_get(
3452+
result = self.gitlab.http_get(
34593453
path, query_data=query_data, streamed=streamed, raw=True, **kwargs
34603454
)
3461-
return utils.response_content(result, streamed, action)
3455+
return utils.response_content(result, streamed, action)
34623456

34633457
@cli.register_custom_action("ProjectFileManager", ("file_path", "ref"))
34643458
@exc.on_http_error(exc.GitlabListError)
@@ -3612,7 +3606,7 @@ def take_ownership(self, **kwargs):
36123606
GitlabOwnershipError: If the request failed
36133607
"""
36143608
path = "%s/%s/take_ownership" % (self.manager.path, self.get_id())
3615-
server_data = return self.manager.gitlab.http_post(path, **kwargs)
3609+
return self.manager.gitlab.http_post(path, **kwargs)
36163610

36173611

36183612
class ProjectPipelineScheduleManager(CRUDMixin, RESTManager):
@@ -3765,10 +3759,10 @@ def content(self, streamed=False, action=None, chunk_size=1024, **kwargs):
37653759
str: The snippet content
37663760
"""
37673761
path = "%s/%s/raw" % (self.manager.path, self.get_id())
3768-
result = self.manager.gitlab.http_get(
3762+
result = self.manager.gitlab.http_get(
37693763
path, streamed=streamed, raw=True, **kwargs
37703764
)
3771-
return utils.response_content(result, streamed, action)
3765+
return utils.response_content(result, streamed, action)
37723766

37733767

37743768
class ProjectSnippetManager(CRUDMixin, RESTManager):
@@ -3906,7 +3900,7 @@ def get(self, id, **kwargs):
39063900
GitlabAuthenticationError: If authentication is not correct
39073901
GitlabGetError: If the server cannot perform the request
39083902
"""
3909-
obj = super(ProjectServiceManager, self).get(id, **kwargs)
3903+
obj = super(ProjectServiceManager, self).get(id, **kwargs)
39103904
obj.id = id
39113905
return obj # TODO: ???
39123906

@@ -3926,7 +3920,7 @@ def update(self, id=None, new_data=None, **kwargs):
39263920
GitlabUpdateError: If the server cannot perform the request
39273921
"""
39283922
new_data = new_data or {}
3929-
super(ProjectServiceManager, self).update(id, new_data, **kwargs)
3923+
super(ProjectServiceManager, self).update(id, new_data, **kwargs)
39303924
self.id = id # TODO: ???
39313925

39323926
@cli.register_custom_action("ProjectServiceManager")
@@ -4085,10 +4079,10 @@ def download(self, streamed=False, action=None, chunk_size=1024, **kwargs):
40854079
str: The blob content if streamed is False, None otherwise
40864080
"""
40874081
path = "/projects/%s/export/download" % self.project_id
4088-
result = self.manager.gitlab.http_get(
4082+
result = self.manager.gitlab.http_get(
40894083
path, streamed=streamed, raw=True, **kwargs
40904084
)
4091-
return utils.response_content(result, streamed, action)
4085+
return utils.response_content(result, streamed, action)
40924086

40934087

40944088
class ProjectExportManager(GetWithoutIdMixin, CreateMixin, RESTManager):
@@ -4276,10 +4270,10 @@ def repository_raw_blob(
42764270
str: The blob content if streamed is False, None otherwise
42774271
"""
42784272
path = "/projects/%s/repository/blobs/%s/raw" % (self.get_id(), sha)
4279-
result = self.manager.gitlab.http_get(
4273+
result = self.manager.gitlab.http_get(
42804274
path, streamed=streamed, raw=True, **kwargs
42814275
)
4282-
return utils.response_content(result, streamed, action)
4276+
return utils.response_content(result, streamed, action)
42834277

42844278
@cli.register_custom_action("Project", ("from_", "to"))
42854279
@exc.on_http_error(exc.GitlabGetError)
@@ -4353,10 +4347,10 @@ def repository_archive(
43534347
query_data = {}
43544348
if sha:
43554349
query_data["sha"] = sha
4356-
result = self.manager.gitlab.http_get(
4350+
result = self.manager.gitlab.http_get(
43574351
path, query_data=query_data, raw=True, streamed=streamed, **kwargs
43584352
)
4359-
return utils.response_content(result, streamed, action)
4353+
return utils.response_content(result, streamed, action)
43604354

43614355
@cli.register_custom_action("Project", ("forked_from_id",))
43624356
@exc.on_http_error(exc.GitlabCreateError)
@@ -4433,7 +4427,7 @@ def star(self, **kwargs):
44334427
GitlabCreateError: If the server failed to perform the request
44344428
"""
44354429
path = "/projects/%s/star" % self.get_id()
4436-
return self.manager.gitlab.http_post(path, **kwargs)
4430+
return self.manager.gitlab.http_post(path, **kwargs)
44374431

44384432
@cli.register_custom_action("Project")
44394433
@exc.on_http_error(exc.GitlabDeleteError)
@@ -4544,7 +4538,7 @@ def trigger_pipeline(self, ref, token, variables=None, **kwargs):
45444538
variables = variables or {}
45454539
path = "/projects/%s/trigger/pipeline" % self.get_id()
45464540
post_data = {"ref": ref, "token": token, "variables": variables}
4547-
attrs = self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
4541+
attrs = self.manager.gitlab.http_post(path, post_data=post_data, **kwargs)
45484542
return ProjectPipeline(self.pipelines, attrs) # TODO: ???
45494543

45504544
@cli.register_custom_action("Project")
@@ -4604,9 +4598,13 @@ def upload(self, filename, filedata=None, filepath=None, **kwargs):
46044598

46054599
url = "/projects/%(id)s/uploads" % {"id": self.id}
46064600
file_info = {"file": (filename, filedata)}
4607-
data = self.manager.gitlab.http_post(url, files=file_info)
4601+
data = self.manager.gitlab.http_post(url, files=file_info)
46084602

4609-
return {"alt": data["alt"], "url": data["url"], "markdown": data["markdown"]} # TODO: ???
4603+
return {
4604+
"alt": data["alt"],
4605+
"url": data["url"],
4606+
"markdown": data["markdown"],
4607+
} # TODO: ???
46104608

46114609
@cli.register_custom_action("Project", optional=("wiki",))
46124610
@exc.on_http_error(exc.GitlabGetError)
@@ -4633,10 +4631,10 @@ def snapshot(
46334631
str: The uncompressed tar archive of the repository
46344632
"""
46354633
path = "/projects/%s/snapshot" % self.get_id()
4636-
result = self.manager.gitlab.http_get(
4634+
result = self.manager.gitlab.http_get(
46374635
path, streamed=streamed, raw=True, **kwargs
46384636
)
4639-
return utils.response_content(result, streamed, action)
4637+
return utils.response_content(result, streamed, action)
46404638

46414639
@cli.register_custom_action("Project", ("scope", "search"))
46424640
@exc.on_http_error(exc.GitlabSearchError)
@@ -4729,7 +4727,7 @@ def artifact(
47294727
result = self.manager.gitlab.http_get(
47304728
path, streamed=streamed, raw=True, **kwargs
47314729
)
4732-
return utils.response_content(result, streamed, action)
4730+
return utils.response_content(result, streamed, action)
47334731

47344732

47354733
class ProjectManager(CRUDMixin, RESTManager):
@@ -5016,7 +5014,7 @@ def mark_as_done(self, **kwargs):
50165014
GitlabTodoError: If the server failed to perform the request
50175015
"""
50185016
path = "%s/%s/mark_as_done" % (self.manager.path, self.id)
5019-
server_data = return self.manager.gitlab.http_post(path, **kwargs)
5017+
return self.manager.gitlab.http_post(path, **kwargs)
50205018

50215019

50225020
class TodoManager(ListMixin, DeleteMixin, RESTManager):

0 commit comments

Comments
 (0)