Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7073a2d

Browse files
JohnVillalovosnejch
authored andcommitted
chore: change_update_uses to_update_method and use an Enum
Change the name of the `_update_uses` attribute to `_update_method`and store an Enum in the attribute to indicate which type of HTTPmethod to use. At the moment it supports `POST` and `PUT`. But can inthe future support `PATCH`.
1 parentb22d662 commit7073a2d

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

‎gitlab/mixins.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
importenum
12
fromtypesimportModuleType
23
fromtypingimport (
34
Any,
@@ -304,14 +305,20 @@ def create(
304305
returnself._obj_cls(self,server_data)
305306

306307

308+
@enum.unique
309+
classUpdateMethod(enum.IntEnum):
310+
PUT=1
311+
POST=2
312+
313+
307314
classUpdateMixin(_RestManagerBase):
308315
_computed_path:Optional[str]
309316
_from_parent_attrs:Dict[str,Any]
310317
_obj_cls:Optional[Type[base.RESTObject]]
311318
_parent:Optional[base.RESTObject]
312319
_parent_attrs:Dict[str,Any]
313320
_path:Optional[str]
314-
_update_uses_post:bool=False
321+
_update_method:UpdateMethod=UpdateMethod.PUT
315322
gitlab:gitlab.Gitlab
316323

317324
def_get_update_method(
@@ -322,7 +329,7 @@ def _get_update_method(
322329
Returns:
323330
http_put (default) or http_post
324331
"""
325-
ifself._update_uses_post:
332+
ifself._update_methodisUpdateMethod.POST:
326333
http_method=self.gitlab.http_post
327334
else:
328335
http_method=self.gitlab.http_put
@@ -894,7 +901,7 @@ class PromoteMixin(_RestObjectBase):
894901
_module:ModuleType
895902
_parent_attrs:Dict[str,Any]
896903
_updated_attrs:Dict[str,Any]
897-
_update_uses_post:bool=False
904+
_update_method:UpdateMethod=UpdateMethod.PUT
898905
manager:base.RESTManager
899906

900907
def_get_update_method(
@@ -905,7 +912,7 @@ def _get_update_method(
905912
Returns:
906913
http_put (default) or http_post
907914
"""
908-
ifself._update_uses_post:
915+
ifself._update_methodisUpdateMethod.POST:
909916
http_method=self.manager.gitlab.http_post
910917
else:
911918
http_method=self.manager.gitlab.http_put

‎gitlab/v4/objects/merge_request_approvals.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
ListMixin,
1111
ObjectDeleteMixin,
1212
SaveMixin,
13+
UpdateMethod,
1314
UpdateMixin,
1415
)
1516
fromgitlab.typesimportRequiredOptional
@@ -45,7 +46,7 @@ class ProjectApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTManager):
4546
"merge_requests_disable_committers_approval",
4647
),
4748
)
48-
_update_uses_post=True
49+
_update_method=UpdateMethod.POST
4950

5051
defget(self,**kwargs:Any)->ProjectApproval:
5152
returncast(ProjectApproval,super().get(**kwargs))
@@ -76,7 +77,7 @@ class ProjectMergeRequestApprovalManager(GetWithoutIdMixin, UpdateMixin, RESTMan
7677
_obj_cls=ProjectMergeRequestApproval
7778
_from_parent_attrs= {"project_id":"project_id","mr_iid":"iid"}
7879
_update_attrs=RequiredOptional(required=("approvals_required",))
79-
_update_uses_post=True
80+
_update_method=UpdateMethod.POST
8081

8182
defget(self,**kwargs:Any)->ProjectMergeRequestApproval:
8283
returncast(ProjectMergeRequestApproval,super().get(**kwargs))

‎gitlab/v4/objects/milestones.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44
fromgitlabimportexceptionsasexc
55
fromgitlabimporttypes
66
fromgitlab.baseimportRESTManager,RESTObject,RESTObjectList
7-
fromgitlab.mixinsimportCRUDMixin,ObjectDeleteMixin,PromoteMixin,SaveMixin
7+
fromgitlab.mixinsimport (
8+
CRUDMixin,
9+
ObjectDeleteMixin,
10+
PromoteMixin,
11+
SaveMixin,
12+
UpdateMethod,
13+
)
814
fromgitlab.typesimportRequiredOptional
915

1016
from .issuesimportGroupIssue,GroupIssueManager,ProjectIssue,ProjectIssueManager
@@ -100,7 +106,7 @@ def get(
100106

101107
classProjectMilestone(PromoteMixin,SaveMixin,ObjectDeleteMixin,RESTObject):
102108
_repr_attr="title"
103-
_update_uses_post=True
109+
_update_method=UpdateMethod.POST
104110

105111
@cli.register_custom_action("ProjectMilestone")
106112
@exc.on_http_error(exc.GitlabListError)

‎tests/unit/mixins/test_mixin_methods.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
RefreshMixin,
1414
SaveMixin,
1515
SetMixin,
16+
UpdateMethod,
1617
UpdateMixin,
1718
)
1819

@@ -377,7 +378,7 @@ class M(UpdateMixin, FakeManager):
377378
@responses.activate
378379
deftest_update_mixin_uses_post(gl):
379380
classM(UpdateMixin,FakeManager):
380-
_update_uses_post=True
381+
_update_method=UpdateMethod.POST
381382

382383
url="http://localhost/api/v4/tests/1"
383384
responses.add(

‎tests/unit/objects/test_project_merge_request_approvals.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
importresponses
99

1010
importgitlab
11+
fromgitlab.mixinsimportUpdateMethod
1112

1213
approval_rule_id=1
1314
approval_rule_name="security"
@@ -157,15 +158,15 @@ def resp_delete_mr_approval_rule():
157158
yieldrsps
158159

159160

160-
deftest_project_approval_manager_update_uses_post(project):
161+
deftest_project_approval_manager_update_method_post(project):
161162
"""Ensure the
162163
gitlab.v4.objects.merge_request_approvals.ProjectApprovalManager object has
163-
_update_uses_post set toTrue"""
164+
_update_method set toUpdateMethod.POST"""
164165
approvals=project.approvals
165166
assertisinstance(
166167
approvals,gitlab.v4.objects.merge_request_approvals.ProjectApprovalManager
167168
)
168-
assertapprovals._update_uses_postisTrue
169+
assertapprovals._update_methodisUpdateMethod.POST
169170

170171

171172
deftest_list_merge_request_approval_rules(project,resp_mr_approval_rules):
@@ -187,7 +188,7 @@ def test_update_merge_request_approvals_set_approvers(project, resp_mr_approval_
187188
approvals,
188189
gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalManager,
189190
)
190-
assertapprovals._update_uses_postisTrue
191+
assertapprovals._update_methodisUpdateMethod.POST
191192
response=approvals.set_approvers(
192193
updated_approval_rule_approvals_required,
193194
approver_ids=updated_approval_rule_user_ids,
@@ -207,7 +208,7 @@ def test_create_merge_request_approvals_set_approvers(project, resp_mr_approval_
207208
approvals,
208209
gitlab.v4.objects.merge_request_approvals.ProjectMergeRequestApprovalManager,
209210
)
210-
assertapprovals._update_uses_postisTrue
211+
assertapprovals._update_methodisUpdateMethod.POST
211212
response=approvals.set_approvers(
212213
new_approval_rule_approvals_required,
213214
approver_ids=new_approval_rule_user_ids,

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp