diff options
| author | John L. Villalovos <john@sodarock.com> | 2022-07-28 21:01:41 -0700 |
|---|---|---|
| committer | John L. Villalovos <john@sodarock.com> | 2022-07-28 21:01:41 -0700 |
| commit | 271f6880dbb15b56305efc1fc73924ac26fb97ad (patch) | |
| tree | f6d9faa21e616d6f77f682e230c6c61395275130 | |
| parent | 69014e9be3a781be6742478af820ea097d004791 (diff) | |
| download | gitlab-271f6880dbb15b56305efc1fc73924ac26fb97ad.tar.gz | |
chore(topics): 'title' is required when creating a topic
In GitLab >= 15.0 `title` is required when creating a topic.
| -rw-r--r-- | docs/gl_objects/topics.rst | 2 | ||||
| -rw-r--r-- | gitlab/v4/objects/topics.py | 5 | ||||
| -rw-r--r-- | tests/functional/api/test_topics.py | 11 | ||||
| -rw-r--r-- | tests/functional/conftest.py | 19 | ||||
| -rw-r--r-- | tests/unit/objects/test_topics.py | 5 |
5 files changed, 37 insertions, 5 deletions
diff --git a/docs/gl_objects/topics.rst b/docs/gl_objects/topics.rst index 0ca46d7..c9a3573 100644 --- a/docs/gl_objects/topics.rst +++ b/docs/gl_objects/topics.rst @@ -30,7 +30,7 @@ Get a specific topic by its ID:: Create a new topic:: - topic = gl.topics.create({"name": "my-topic"}) + topic = gl.topics.create({"name": "my-topic", "title": "my title"}) Update a topic:: diff --git a/gitlab/v4/objects/topics.py b/gitlab/v4/objects/topics.py index 57b104e..143759d 100644 --- a/gitlab/v4/objects/topics.py +++ b/gitlab/v4/objects/topics.py @@ -19,7 +19,10 @@ class TopicManager(CRUDMixin, RESTManager): _path = "/topics" _obj_cls = Topic _create_attrs = RequiredOptional( - required=("name",), optional=("avatar", "description") + # NOTE: The `title` field was added and is required in GitLab 15.0 or + # newer. But not present before that. + required=("name",), + optional=("avatar", "description", "title"), ) _update_attrs = RequiredOptional(optional=("avatar", "description", "name")) _types = {"avatar": types.ImageAttribute} diff --git a/tests/functional/api/test_topics.py b/tests/functional/api/test_topics.py index 7ad71a5..0d6a3ef 100644 --- a/tests/functional/api/test_topics.py +++ b/tests/functional/api/test_topics.py @@ -4,11 +4,18 @@ https://docs.gitlab.com/ce/api/topics.html """ -def test_topics(gl): +def test_topics(gl, gitlab_version): assert not gl.topics.list() - topic = gl.topics.create({"name": "my-topic", "description": "My Topic"}) + create_dict = {"name": "my-topic", "description": "My Topic"} + if gitlab_version.major >= 15: + create_dict["title"] = "my topic title" + topic = gl.topics.create( + {"name": "my-topic", "title": "my topic title", "description": "My Topic"} + ) assert topic.name == "my-topic" + if gitlab_version.major >= 15: + assert topic.title == "my topic title" assert gl.topics.list() topic.description = "My Updated Topic" diff --git a/tests/functional/conftest.py b/tests/functional/conftest.py index 2767b9d..dc4422e 100644 --- a/tests/functional/conftest.py +++ b/tests/functional/conftest.py @@ -1,3 +1,4 @@ +import dataclasses import logging import tempfile import time @@ -12,6 +13,24 @@ import gitlab.base from tests.functional import helpers +@dataclasses.dataclass +class GitlabVersion: + major: int + minor: int + patch: str + revision: str + + def __post_init__(self): + self.major, self.minor = int(self.major), int(self.minor) + + +@pytest.fixture(scope="session") +def gitlab_version(gl) -> GitlabVersion: + version, revision = gl.version() + major, minor, patch = version.split(".") + return GitlabVersion(major=major, minor=minor, patch=patch, revision=revision) + + @pytest.fixture(scope="session") def fixture_dir(test_dir): return test_dir / "functional" / "fixtures" diff --git a/tests/unit/objects/test_topics.py b/tests/unit/objects/test_topics.py index 14b2cfd..46e964e 100644 --- a/tests/unit/objects/test_topics.py +++ b/tests/unit/objects/test_topics.py @@ -8,10 +8,12 @@ import responses from gitlab.v4.objects import Topic name = "GitLab" +topic_title = "topic title" new_name = "gitlab-test" topic_content = { "id": 1, "name": name, + "title": topic_title, "description": "GitLab is an open source end-to-end software development platform.", "total_projects_count": 1000, "avatar_url": "http://www.gravatar.com/avatar/a0d477b3ea21970ce6ffcbb817b0b435?s=80&d=identicon", @@ -102,9 +104,10 @@ def test_get_topic(gl, resp_get_topic): def test_create_topic(gl, resp_create_topic): - topic = gl.topics.create({"name": name}) + topic = gl.topics.create({"name": name, "title": topic_title}) assert isinstance(topic, Topic) assert topic.name == name + assert topic.title == topic_title def test_update_topic(gl, resp_update_topic): |
