summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects/test_pipeline_schedules.py
blob: 6b56304152d8884e698e2950110c3b8b5be5e060 (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
"""
GitLab API: https://docs.gitlab.com/ce/api/pipeline_schedules.html
"""

from httmock import response, urlmatch, with_httmock

from .mocks import headers


@urlmatch(
    scheme="http",
    netloc="localhost",
    path="/api/v4/projects/1/pipeline_schedules$",
    method="post",
)
def resp_create_project_pipeline_schedule(url, request):
    """Mock for creating project pipeline Schedules POST response."""
    content = """{
    "id": 14,
    "description": "Build packages",
    "ref": "master",
    "cron": "0 1 * * 5",
    "cron_timezone": "UTC",
    "next_run_at": "2017-05-26T01:00:00.000Z",
    "active": true,
    "created_at": "2017-05-19T13:43:08.169Z",
    "updated_at": "2017-05-19T13:43:08.169Z",
    "last_pipeline": null,
    "owner": {
        "name": "Administrator",
        "username": "root",
        "id": 1,
        "state": "active",
        "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
        "web_url": "https://gitlab.example.com/root"
    }
}"""
    content = content.encode("utf-8")
    return response(200, content, headers, None, 5, request)


@urlmatch(
    scheme="http",
    netloc="localhost",
    path="/api/v4/projects/1/pipeline_schedules/14/play",
    method="post",
)
def resp_play_project_pipeline_schedule(url, request):
    """Mock for playing a project pipeline schedule POST response."""
    content = """{"message": "201 Created"}"""
    content = content.encode("utf-8")
    return response(200, content, headers, None, 5, request)


@with_httmock(
    resp_create_project_pipeline_schedule, resp_play_project_pipeline_schedule
)
def test_project_pipeline_schedule_play(project):
    description = "Build packages"
    cronline = "0 1 * * 5"
    sched = project.pipelineschedules.create(
        {"ref": "master", "description": description, "cron": cronline}
    )
    assert sched is not None
    assert description == sched.description
    assert cronline == sched.cron

    play_result = sched.play()
    assert play_result is not None
    assert "message" in play_result
    assert play_result["message"] == "201 Created"