From 88f8cc78f97156d5888a9600bdb8721720563120 Mon Sep 17 00:00:00 2001 From: Oleksii Shkurupii Date: Wed, 26 Aug 2020 13:37:03 +0300 Subject: feat: add support to resource milestone events Fixes #1154 --- gitlab/v4/objects.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'gitlab') diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 2f3e8a5..16efc39 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -2654,6 +2654,16 @@ class ProjectIssueResourceLabelEventManager(RetrieveMixin, RESTManager): _from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"} +class ProjectIssueResourceMilestoneEvent(RESTObject): + pass + + +class ProjectIssueResourceMilestoneEventManager(RetrieveMixin, RESTManager): + _path = "/projects/%(project_id)s/issues/%(issue_iid)s/resource_milestone_events" + _obj_cls = ProjectIssueResourceMilestoneEvent + _from_parent_attrs = {"project_id": "project_id", "issue_iid": "iid"} + + class ProjectIssue( UserAgentDetailMixin, SubscribableMixin, @@ -2672,6 +2682,7 @@ class ProjectIssue( ("links", "ProjectIssueLinkManager"), ("notes", "ProjectIssueNoteManager"), ("resourcelabelevents", "ProjectIssueResourceLabelEventManager"), + ("resourcemilestoneevents", "ProjectIssueResourceMilestoneEventManager"), ) @cli.register_custom_action("ProjectIssue", ("to_project_id",)) @@ -3065,6 +3076,18 @@ class ProjectMergeRequestResourceLabelEventManager(RetrieveMixin, RESTManager): _from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"} +class ProjectMergeRequestResourceMilestoneEvent(RESTObject): + pass + + +class ProjectMergeRequestResourceMilestoneEventManager(RetrieveMixin, RESTManager): + _path = ( + "/projects/%(project_id)s/merge_requests/%(mr_iid)s/resource_milestone_events" + ) + _obj_cls = ProjectMergeRequestResourceMilestoneEvent + _from_parent_attrs = {"project_id": "project_id", "mr_iid": "iid"} + + class ProjectMergeRequest( SubscribableMixin, TodoMixin, @@ -3083,6 +3106,7 @@ class ProjectMergeRequest( ("discussions", "ProjectMergeRequestDiscussionManager"), ("notes", "ProjectMergeRequestNoteManager"), ("resourcelabelevents", "ProjectMergeRequestResourceLabelEventManager"), + ("resourcemilestoneevents", "ProjectMergeRequestResourceMilestoneEventManager"), ) @cli.register_custom_action("ProjectMergeRequest") -- cgit v1.2.1 From 1317f4b62afefcb2504472d5b5d8e24f39b0d86f Mon Sep 17 00:00:00 2001 From: Oleksii Shkurupii Date: Fri, 28 Aug 2020 19:05:54 +0300 Subject: test: add unit tests for resource milestone events API Fixes #1154 --- .../objects/test_resource_milestone_events.py | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 gitlab/tests/objects/test_resource_milestone_events.py (limited to 'gitlab') diff --git a/gitlab/tests/objects/test_resource_milestone_events.py b/gitlab/tests/objects/test_resource_milestone_events.py new file mode 100644 index 0000000..99faeaa --- /dev/null +++ b/gitlab/tests/objects/test_resource_milestone_events.py @@ -0,0 +1,73 @@ +""" +GitLab API: https://docs.gitlab.com/ee/api/resource_milestone_events.html +""" + +import pytest +import responses + +from gitlab.v4.objects import ( + ProjectIssueResourceMilestoneEvent, + ProjectMergeRequestResourceMilestoneEvent, +) + + +@pytest.fixture() +def resp_merge_request_milestone_events(): + mr_content = {"iid": 1} + events_content = {"id": 1, "resource_type": "MergeRequest"} + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/merge_requests", + json=[mr_content], + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/merge_requests/1/resource_milestone_events", + json=[events_content], + content_type="application/json", + status=200, + ) + yield rsps + + +@pytest.fixture() +def resp_project_issue_milestone_events(): + issue_content = {"iid": 1} + events_content = {"id": 1, "resource_type": "Issue"} + with responses.RequestsMock() as rsps: + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/issues", + json=[issue_content], + content_type="application/json", + status=200, + ) + rsps.add( + method=responses.GET, + url="http://localhost/api/v4/projects/1/issues/1/resource_milestone_events", + json=[events_content], + content_type="application/json", + status=200, + ) + yield rsps + + +def test_project_issue_milestone_events(project, resp_project_issue_milestone_events): + issue = project.issues.list()[0] + milestone_events = issue.resourcemilestoneevents.list() + assert isinstance(milestone_events, list) + milestone_event = milestone_events[0] + assert isinstance(milestone_event, ProjectIssueResourceMilestoneEvent) + assert milestone_event.resource_type == "Issue" + + +def test_merge_request_milestone_events(project, resp_merge_request_milestone_events): + mr = project.mergerequests.list()[0] + milestone_events = mr.resourcemilestoneevents.list() + assert isinstance(milestone_events, list) + milestone_event = milestone_events[0] + assert isinstance(milestone_event, ProjectMergeRequestResourceMilestoneEvent) + assert milestone_event.resource_type == "MergeRequest" -- cgit v1.2.1 From 696147922552a8e6ddda3a5b852ee2de6b983e37 Mon Sep 17 00:00:00 2001 From: Oleksii Shkurupii Date: Sat, 29 Aug 2020 10:08:40 +0300 Subject: chore: make latest black happy with existing code --- gitlab/tests/objects/test_commits.py | 8 +++++++- gitlab/tests/objects/test_runners.py | 12 +++++++++--- gitlab/v4/objects.py | 26 +++++++++++++++++++++----- 3 files changed, 37 insertions(+), 9 deletions(-) (limited to 'gitlab') diff --git a/gitlab/tests/objects/test_commits.py b/gitlab/tests/objects/test_commits.py index 9d11508..6b98117 100644 --- a/gitlab/tests/objects/test_commits.py +++ b/gitlab/tests/objects/test_commits.py @@ -88,7 +88,13 @@ def test_create_commit(project, resp_create_commit): data = { "branch": "master", "commit_message": "Commit message", - "actions": [{"action": "create", "file_path": "README", "content": "",}], + "actions": [ + { + "action": "create", + "file_path": "README", + "content": "", + } + ], } commit = project.commits.create(data) assert commit.short_id == "ed899a2f" diff --git a/gitlab/tests/objects/test_runners.py b/gitlab/tests/objects/test_runners.py index 490ba36..30fdb41 100644 --- a/gitlab/tests/objects/test_runners.py +++ b/gitlab/tests/objects/test_runners.py @@ -167,7 +167,9 @@ def resp_runner_delete(): status=200, ) rsps.add( - method=responses.DELETE, url=pattern, status=204, + method=responses.DELETE, + url=pattern, + status=204, ) yield rsps @@ -177,7 +179,9 @@ def resp_runner_disable(): with responses.RequestsMock() as rsps: pattern = re.compile(r".*?/(groups|projects)/1/runners/6") rsps.add( - method=responses.DELETE, url=pattern, status=204, + method=responses.DELETE, + url=pattern, + status=204, ) yield rsps @@ -187,7 +191,9 @@ def resp_runner_verify(): with responses.RequestsMock() as rsps: pattern = re.compile(r".*?/runners/verify") rsps.add( - method=responses.POST, url=pattern, status=200, + method=responses.POST, + url=pattern, + status=200, ) yield rsps diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 9893d1d..e515ea1 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -711,8 +711,14 @@ class ProjectDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager _from_parent_attrs = {"project_id": "id"} _obj_cls = ProjectDeployToken _create_attrs = ( - ("name", "scopes",), - ("expires_at", "username",), + ( + "name", + "scopes", + ), + ( + "expires_at", + "username", + ), ) @@ -725,8 +731,14 @@ class GroupDeployTokenManager(ListMixin, CreateMixin, DeleteMixin, RESTManager): _from_parent_attrs = {"group_id": "id"} _obj_cls = GroupDeployToken _create_attrs = ( - ("name", "scopes",), - ("expires_at", "username",), + ( + "name", + "scopes", + ), + ( + "expires_at", + "username", + ), ) @@ -4205,7 +4217,11 @@ class ProjectServiceManager(GetMixin, UpdateMixin, DeleteMixin, ListMixin, RESTM ), ), "jira": ( - ("url", "username", "password",), + ( + "url", + "username", + "password", + ), ( "api_url", "active", -- cgit v1.2.1