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


@pytest.fixture
def resp_project_pipeline_schedule(created_content):
    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": None,
        "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",
        },
    }

    with responses.RequestsMock() as rsps:
        rsps.add(
            method=responses.POST,
            url="http://localhost/api/v4/projects/1/pipeline_schedules",
            json=content,
            content_type="application/json",
            status=200,
        )
        rsps.add(
            method=responses.POST,
            url="http://localhost/api/v4/projects/1/pipeline_schedules/14/play",
            json=created_content,
            content_type="application/json",
            status=201,
        )
        yield rsps


def test_project_pipeline_schedule_play(project, resp_project_pipeline_schedule):
    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"