Skip to content

Commit 1317f4b

Browse files
Oleksii ShkurupiiOleksii Shkurupii
authored andcommitted
test: add unit tests for resource milestone events API
Fixes #1154
1 parent fa899d7 commit 1317f4b

File tree

1 file changed

+73
-0
lines changed

1 file changed

+73
-0
lines changed
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/resource_milestone_events.html
3+
"""
4+
5+
import pytest
6+
import responses
7+
8+
from gitlab.v4.objects import (
9+
ProjectIssueResourceMilestoneEvent,
10+
ProjectMergeRequestResourceMilestoneEvent,
11+
)
12+
13+
14+
@pytest.fixture()
15+
def resp_merge_request_milestone_events():
16+
mr_content = {"iid": 1}
17+
events_content = {"id": 1, "resource_type": "MergeRequest"}
18+
with responses.RequestsMock() as rsps:
19+
rsps.add(
20+
method=responses.GET,
21+
url="http://localhost/api/v4/projects/1/merge_requests",
22+
json=[mr_content],
23+
content_type="application/json",
24+
status=200,
25+
)
26+
rsps.add(
27+
method=responses.GET,
28+
url="http://localhost/api/v4/projects/1/merge_requests/1/resource_milestone_events",
29+
json=[events_content],
30+
content_type="application/json",
31+
status=200,
32+
)
33+
yield rsps
34+
35+
36+
@pytest.fixture()
37+
def resp_project_issue_milestone_events():
38+
issue_content = {"iid": 1}
39+
events_content = {"id": 1, "resource_type": "Issue"}
40+
with responses.RequestsMock() as rsps:
41+
rsps.add(
42+
method=responses.GET,
43+
url="http://localhost/api/v4/projects/1/issues",
44+
json=[issue_content],
45+
content_type="application/json",
46+
status=200,
47+
)
48+
rsps.add(
49+
method=responses.GET,
50+
url="http://localhost/api/v4/projects/1/issues/1/resource_milestone_events",
51+
json=[events_content],
52+
content_type="application/json",
53+
status=200,
54+
)
55+
yield rsps
56+
57+
58+
def test_project_issue_milestone_events(project, resp_project_issue_milestone_events):
59+
issue = project.issues.list()[0]
60+
milestone_events = issue.resourcemilestoneevents.list()
61+
assert isinstance(milestone_events, list)
62+
milestone_event = milestone_events[0]
63+
assert isinstance(milestone_event, ProjectIssueResourceMilestoneEvent)
64+
assert milestone_event.resource_type == "Issue"
65+
66+
67+
def test_merge_request_milestone_events(project, resp_merge_request_milestone_events):
68+
mr = project.mergerequests.list()[0]
69+
milestone_events = mr.resourcemilestoneevents.list()
70+
assert isinstance(milestone_events, list)
71+
milestone_event = milestone_events[0]
72+
assert isinstance(milestone_event, ProjectMergeRequestResourceMilestoneEvent)
73+
assert milestone_event.resource_type == "MergeRequest"

0 commit comments

Comments
 (0)