summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-04-01 11:10:30 +0200
committerJohn Villalovos <john@sodarock.com>2022-04-01 08:22:19 -0700
commitd1d96bda5f1c6991c8ea61dca8f261e5b74b5ab6 (patch)
tree10826fedd12e4dc722c35bda11084fead8c5ceb9
parent8db68411d6444787ca339cf50dd96b2ab41de60c (diff)
downloadgitlab-d1d96bda5f1c6991c8ea61dca8f261e5b74b5ab6.tar.gz
feat(api): re-add topic delete endpoint
This reverts commit e3035a799a484f8d6c460f57e57d4b59217cd6de.
-rw-r--r--docs/gl_objects/topics.rst7
-rw-r--r--gitlab/v4/objects/topics.py6
-rw-r--r--tests/functional/api/test_topics.py3
-rw-r--r--tests/functional/conftest.py2
-rw-r--r--tests/unit/objects/test_topics.py18
5 files changed, 33 insertions, 3 deletions
diff --git a/docs/gl_objects/topics.rst b/docs/gl_objects/topics.rst
index 5765d63..0ca46d7 100644
--- a/docs/gl_objects/topics.rst
+++ b/docs/gl_objects/topics.rst
@@ -39,3 +39,10 @@ Update a topic::
# or
gl.topics.update(topic_id, {"description": "My new topic"})
+
+Delete a topic::
+
+ topic.delete()
+
+ # or
+ gl.topics.delete(topic_id)
diff --git a/gitlab/v4/objects/topics.py b/gitlab/v4/objects/topics.py
index 71f6607..76208ed 100644
--- a/gitlab/v4/objects/topics.py
+++ b/gitlab/v4/objects/topics.py
@@ -2,7 +2,7 @@ from typing import Any, cast, Union
from gitlab import types
from gitlab.base import RequiredOptional, RESTManager, RESTObject
-from gitlab.mixins import CreateMixin, RetrieveMixin, SaveMixin, UpdateMixin
+from gitlab.mixins import CRUDMixin, ObjectDeleteMixin, SaveMixin
__all__ = [
"Topic",
@@ -10,11 +10,11 @@ __all__ = [
]
-class Topic(SaveMixin, RESTObject):
+class Topic(SaveMixin, ObjectDeleteMixin, RESTObject):
pass
-class TopicManager(CreateMixin, RetrieveMixin, UpdateMixin, RESTManager):
+class TopicManager(CRUDMixin, RESTManager):
_path = "/topics"
_obj_cls = Topic
_create_attrs = RequiredOptional(
diff --git a/tests/functional/api/test_topics.py b/tests/functional/api/test_topics.py
index dea457c..7ad71a5 100644
--- a/tests/functional/api/test_topics.py
+++ b/tests/functional/api/test_topics.py
@@ -16,3 +16,6 @@ def test_topics(gl):
updated_topic = gl.topics.get(topic.id)
assert updated_topic.description == topic.description
+
+ topic.delete()
+ assert not gl.topics.list()
diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py
index ca589f2..e43b53b 100644
--- a/tests/functional/conftest.py
+++ b/tests/functional/conftest.py
@@ -39,6 +39,8 @@ def reset_gitlab(gl):
)
deploy_token.delete()
group.delete()
+ for topic in gl.topics.list():
+ topic.delete()
for variable in gl.variables.list():
logging.info(f"Marking for deletion variable: {variable.key!r}")
variable.delete()
diff --git a/tests/unit/objects/test_topics.py b/tests/unit/objects/test_topics.py
index c0654ac..14b2cfd 100644
--- a/tests/unit/objects/test_topics.py
+++ b/tests/unit/objects/test_topics.py
@@ -75,6 +75,19 @@ def resp_update_topic():
yield rsps
+@pytest.fixture
+def resp_delete_topic(no_content):
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.DELETE,
+ url=topic_url,
+ json=no_content,
+ content_type="application/json",
+ status=204,
+ )
+ yield rsps
+
+
def test_list_topics(gl, resp_list_topics):
topics = gl.topics.list()
assert isinstance(topics, list)
@@ -99,3 +112,8 @@ def test_update_topic(gl, resp_update_topic):
topic.name = new_name
topic.save()
assert topic.name == new_name
+
+
+def test_delete_topic(gl, resp_delete_topic):
+ topic = gl.topics.get(1, lazy=True)
+ topic.delete()