summaryrefslogtreecommitdiff
path: root/tests/unit/objects/test_resource_milestone_events.py
blob: 99faeaa6599083c2e9a74df0facb25e5913ed7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
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"