|
| 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