44import pytest
55import responses
66
7+ from gitlab .v4 .objects import ProjectPipelineSchedulePipeline
8+
9+ pipeline_content = {
10+ "id" :48 ,
11+ "iid" :13 ,
12+ "project_id" :29 ,
13+ "status" :"pending" ,
14+ "source" :"scheduled" ,
15+ "ref" :"new-pipeline" ,
16+ "sha" :"eb94b618fb5865b26e80fdd8ae531b7a63ad851a" ,
17+ "web_url" :"https://example.com/foo/bar/pipelines/48" ,
18+ "created_at" :"2016-08-12T10:06:04.561Z" ,
19+ "updated_at" :"2016-08-12T10:09:56.223Z" ,
20+ }
21+
722
823@pytest .fixture
9- def resp_project_pipeline_schedule ( created_content ):
24+ def resp_create_pipeline_schedule ( ):
1025content = {
1126"id" :14 ,
1227"description" :"Build packages" ,
@@ -36,17 +51,36 @@ def resp_project_pipeline_schedule(created_content):
3651content_type = "application/json" ,
3752status = 200 ,
3853 )
54+ yield rsps
55+
56+
57+ @pytest .fixture
58+ def resp_play_pipeline_schedule (created_content ):
59+ with responses .RequestsMock ()as rsps :
3960rsps .add (
4061method = responses .POST ,
41- url = "http://localhost/api/v4/projects/1/pipeline_schedules/14 /play" ,
62+ url = "http://localhost/api/v4/projects/1/pipeline_schedules/1 /play" ,
4263json = created_content ,
4364content_type = "application/json" ,
4465status = 201 ,
4566 )
4667yield rsps
4768
4869
49- def test_project_pipeline_schedule_play (project ,resp_project_pipeline_schedule ):
70+ @pytest .fixture
71+ def resp_list_schedule_pipelines ():
72+ with responses .RequestsMock ()as rsps :
73+ rsps .add (
74+ method = responses .GET ,
75+ url = "http://localhost/api/v4/projects/1/pipeline_schedules/1/pipelines" ,
76+ json = [pipeline_content ],
77+ content_type = "application/json" ,
78+ status = 200 ,
79+ )
80+ yield rsps
81+
82+
83+ def test_create_project_pipeline_schedule (project ,resp_create_pipeline_schedule ):
5084description = "Build packages"
5185cronline = "0 1 * * 5"
5286sched = project .pipelineschedules .create (
@@ -56,7 +90,18 @@ def test_project_pipeline_schedule_play(project, resp_project_pipeline_schedule)
5690assert description == sched .description
5791assert cronline == sched .cron
5892
59- play_result = sched .play ()
93+
94+ def test_play_project_pipeline_schedule (schedule ,resp_play_pipeline_schedule ):
95+ play_result = schedule .play ()
6096assert play_result is not None
6197assert "message" in play_result
6298assert play_result ["message" ]== "201 Created"
99+
100+
101+ def test_list_project_pipeline_schedule_pipelines (
102+ schedule ,resp_list_schedule_pipelines
103+ ):
104+ pipelines = schedule .pipelines .list ()
105+ assert isinstance (pipelines ,list )
106+ assert isinstance (pipelines [0 ],ProjectPipelineSchedulePipeline )
107+ assert pipelines [0 ].source == "scheduled"