◐ Shell
reader mode source ↗
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
File filter
Conversations
Jump to
Diff view
Apply and reload
Show whitespace
Diff view
Apply and reload
15 changes: 14 additions & 1 deletion gitlab/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import textwrap
from collections.abc import Iterable
from types import ModuleType
from typing import Any, ClassVar, Generic, TYPE_CHECKING, TypeVar

import gitlab
from gitlab import types as g_types
Expand Down Expand Up @@ -351,6 +351,7 @@ class RESTManager(Generic[TObjCls]):
_path: ClassVar[str]
_obj_cls: type[TObjCls]
_from_parent_attrs: dict[str, Any] = {}
_types: dict[str, type[g_types.GitlabAttribute]] = {}

_computed_path: str
Expand Down Expand Up @@ -389,6 +390,18 @@ def _compute_path(self, path: str | None = None) -> str:
self._parent_attrs = data
return path.format(**data)

@property
def path(self) -> str:
return self._computed_path
40 changes: 35 additions & 5 deletions gitlab/v4/objects/merge_trains.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,44 @@
from gitlab.base import RESTObject
from gitlab.mixins import ListMixin

__all__ = ["ProjectMergeTrain", "ProjectMergeTrainManager"]


class ProjectMergeTrain(RESTObject):
pass


class ProjectMergeTrainManager(ListMixin[ProjectMergeTrain]):
_path = "/projects/{project_id}/merge_trains"
_obj_cls = ProjectMergeTrain
_from_parent_attrs = {"project_id": "id"}
Expand Down
99 changes: 98 additions & 1 deletion tests/unit/mixins/test_mixin_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,6 @@ class TestClass(UploadMixin, FakeObject):
url=url,
json={"id": 42, "file_name": "test.txt", "file_content": "testing contents"},
status=200,
match=[responses.matchers.query_param_matcher({})],
)

mgr = FakeManager(gl)
Expand All @@ -596,3 +595,101 @@ class TestClass(UploadMixin, FakeObject):
assert res_only_path["file_name"] == "test.txt"
assert res_only_path["file_content"] == "testing contents"
assert responses.assert_call_count(url, 1) is True
65 changes: 63 additions & 2 deletions tests/unit/objects/test_merge_trains.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@
https://docs.gitlab.com/ee/api/merge_trains.html
"""

import pytest
import responses

from gitlab.v4.objects import ProjectMergeTrain

mr_content = {
"id": 110,
"merge_request": {
"id": 1,
"iid": 1,
"project_id": 3,
"title": "Test merge train",
Expand Down Expand Up @@ -46,6 +48,10 @@
"duration": 70,
}


@pytest.fixture
def resp_list_merge_trains():
Expand All @@ -60,7 +66,62 @@ def resp_list_merge_trains():
yield rsps


def test_list_project_merge_requests(project, resp_list_merge_trains):
merge_trains = project.merge_trains.list()
assert isinstance(merge_trains[0], ProjectMergeTrain)
assert merge_trains[0].id == mr_content["id"]
Toggle all file notes Toggle all file annotations