Skip to content

Commit 3870af8

Browse files
fix: remove custom delete method for labels
The usage of deleting was incorrect according to the current API. Add tests to show it works with labels needing to be encoded. Also enable the test_group_labels() test function. Previously it was disabled. Closes: #1867
1 parent 7646360 commit 3870af8

File tree

3 files changed

+11
-42
lines changed

3 files changed

+11
-42
lines changed

gitlab/v4/objects/labels.py

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any, cast, Dict, Optional, TYPE_CHECKING, Union
1+
from typing import Any, cast, Dict, Optional, Union
22

33
from gitlab import exceptions as exc
44
from gitlab.base import RequiredOptional, RESTManager, RESTObject
@@ -78,25 +78,6 @@ def update( # type: ignore
7878
new_data["name"] = name
7979
return super().update(id=None, new_data=new_data, **kwargs)
8080

81-
# Delete without ID.
82-
@exc.on_http_error(exc.GitlabDeleteError)
83-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
84-
# type error
85-
def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
86-
"""Delete a Label on the server.
87-
88-
Args:
89-
name: The name of the label
90-
**kwargs: Extra options to send to the server (e.g. sudo)
91-
92-
Raises:
93-
GitlabAuthenticationError: If authentication is not correct
94-
GitlabDeleteError: If the server cannot perform the request
95-
"""
96-
if TYPE_CHECKING:
97-
assert self.path is not None
98-
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)
99-
10081

10182
class ProjectLabel(
10283
PromoteMixin, SubscribableMixin, SaveMixin, ObjectDeleteMixin, RESTObject
@@ -162,22 +143,3 @@ def update( # type: ignore
162143
if name:
163144
new_data["name"] = name
164145
return super().update(id=None, new_data=new_data, **kwargs)
165-
166-
# Delete without ID.
167-
@exc.on_http_error(exc.GitlabDeleteError)
168-
# NOTE(jlvillal): Signature doesn't match DeleteMixin.delete() so ignore
169-
# type error
170-
def delete(self, name: str, **kwargs: Any) -> None: # type: ignore
171-
"""Delete a Label on the server.
172-
173-
Args:
174-
name: The name of the label
175-
**kwargs: Extra options to send to the server (e.g. sudo)
176-
177-
Raises:
178-
GitlabAuthenticationError: If authentication is not correct
179-
GitlabDeleteError: If the server cannot perform the request
180-
"""
181-
if TYPE_CHECKING:
182-
assert self.path is not None
183-
self.gitlab.http_delete(self.path, query_data={"name": name}, **kwargs)

tests/functional/api/test_groups.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ def test_groups(gl):
104104
group2.members.delete(gl.user.id)
105105

106106

107-
@pytest.mark.skip(reason="Commented out in legacy test")
108107
def test_group_labels(group):
109108
group.labels.create({"name": "foo", "description": "bar", "color": "#112233"})
110109
label = group.labels.get("foo")
@@ -116,6 +115,12 @@ def test_group_labels(group):
116115
assert label.description == "baz"
117116
assert len(group.labels.list()) == 1
118117

118+
label.new_name = "comp:Flat Export"
119+
label.save()
120+
assert label.name == "comp:Flat Export"
121+
label = group.labels.get("comp:Flat Export")
122+
assert label.name == "comp:Flat Export"
123+
119124
label.delete()
120125
assert len(group.labels.list()) == 0
121126

tests/functional/api/test_projects.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,11 @@ def test_project_labels(project):
146146
label = project.labels.get("label")
147147
assert label == labels[0]
148148

149-
label.new_name = "labelupdated"
149+
label.new_name = "comp:Flat Export"
150150
label.save()
151-
assert label.name == "labelupdated"
151+
assert label.name == "comp:Flat Export"
152+
label = project.labels.get("comp:Flat Export")
153+
assert label.name == "comp:Flat Export"
152154

153155
label.subscribe()
154156
assert label.subscribed is True

0 commit comments

Comments
 (0)