Skip to content

Commit c1f6e51

Browse files
committed
test(objects): add tests for resource state events
1 parent 0e1e448 commit c1f6e51

File tree

2 files changed

+115
-0
lines changed

2 files changed

+115
-0
lines changed

gitlab/tests/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,16 @@ def project(gl):
5252
return gl.projects.get(1, lazy=True)
5353

5454

55+
@pytest.fixture
56+
def project_issue(project):
57+
return project.issues.get(1, lazy=True)
58+
59+
60+
@pytest.fixture
61+
def project_merge_request(project):
62+
return project.mergerequests.get(1, lazy=True)
63+
64+
5565
@pytest.fixture
5666
def release(project, tag_name):
5767
return project.releases.get(tag_name, lazy=True)
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
"""
2+
GitLab API: https://docs.gitlab.com/ee/api/resource_state_events.html
3+
"""
4+
5+
import pytest
6+
import responses
7+
8+
from gitlab.v4.objects import (
9+
ProjectIssueResourceStateEvent,
10+
ProjectMergeRequestResourceStateEvent,
11+
)
12+
13+
14+
issue_event_content = {"id": 1, "resource_type": "Issue"}
15+
mr_event_content = {"id": 1, "resource_type": "MergeRequest"}
16+
17+
18+
@pytest.fixture()
19+
def resp_list_project_issue_state_events():
20+
with responses.RequestsMock() as rsps:
21+
rsps.add(
22+
method=responses.GET,
23+
url="http://localhost/api/v4/projects/1/issues/1/resource_state_events",
24+
json=[issue_event_content],
25+
content_type="application/json",
26+
status=200,
27+
)
28+
yield rsps
29+
30+
31+
@pytest.fixture()
32+
def resp_get_project_issue_state_event():
33+
with responses.RequestsMock() as rsps:
34+
rsps.add(
35+
method=responses.GET,
36+
url="http://localhost/api/v4/projects/1/issues/1/resource_state_events/1",
37+
json=issue_event_content,
38+
content_type="application/json",
39+
status=200,
40+
)
41+
yield rsps
42+
43+
44+
@pytest.fixture()
45+
def resp_list_merge_request_state_events():
46+
with responses.RequestsMock() as rsps:
47+
rsps.add(
48+
method=responses.GET,
49+
url="http://localhost/api/v4/projects/1/merge_requests/1/resource_state_events",
50+
json=[mr_event_content],
51+
content_type="application/json",
52+
status=200,
53+
)
54+
yield rsps
55+
56+
57+
@pytest.fixture()
58+
def resp_get_merge_request_state_event():
59+
with responses.RequestsMock() as rsps:
60+
rsps.add(
61+
method=responses.GET,
62+
url="http://localhost/api/v4/projects/1/merge_requests/1/resource_state_events/1",
63+
json=mr_event_content,
64+
content_type="application/json",
65+
status=200,
66+
)
67+
yield rsps
68+
69+
70+
def test_list_project_issue_state_events(
71+
project_issue, resp_list_project_issue_state_events
72+
):
73+
state_events = project_issue.resourcestateevents.list()
74+
assert isinstance(state_events, list)
75+
76+
state_event = state_events[0]
77+
assert isinstance(state_event, ProjectIssueResourceStateEvent)
78+
assert state_event.resource_type == "Issue"
79+
80+
81+
def test_get_project_issue_state_event(
82+
project_issue, resp_get_project_issue_state_event
83+
):
84+
state_event = project_issue.resourcestateevents.get(1)
85+
assert isinstance(state_event, ProjectIssueResourceStateEvent)
86+
assert state_event.resource_type == "Issue"
87+
88+
89+
def test_list_merge_request_state_events(
90+
project_merge_request, resp_list_merge_request_state_events
91+
):
92+
state_events = project_merge_request.resourcestateevents.list()
93+
assert isinstance(state_events, list)
94+
95+
state_event = state_events[0]
96+
assert isinstance(state_event, ProjectMergeRequestResourceStateEvent)
97+
assert state_event.resource_type == "MergeRequest"
98+
99+
100+
def test_get_merge_request_state_event(
101+
project_merge_request, resp_get_merge_request_state_event
102+
):
103+
state_event = project_merge_request.resourcestateevents.get(1)
104+
assert isinstance(state_event, ProjectMergeRequestResourceStateEvent)
105+
assert state_event.resource_type == "MergeRequest"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy