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 ( ):
1025 content = {
1126 "id" : 14 ,
1227 "description" : "Build packages" ,
@@ -36,17 +51,36 @@ def resp_project_pipeline_schedule(created_content):
3651 content_type = "application/json" ,
3752 status = 200 ,
3853 )
54+ yield rsps
55+
56+
57+ @pytest .fixture
58+ def resp_play_pipeline_schedule (created_content ):
59+ with responses .RequestsMock () as rsps :
3960 rsps .add (
4061 method = 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" ,
4263 json = created_content ,
4364 content_type = "application/json" ,
4465 status = 201 ,
4566 )
4667 yield 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 ):
5084 description = "Build packages"
5185 cronline = "0 1 * * 5"
5286 sched = project .pipelineschedules .create (
@@ -56,7 +90,18 @@ def test_project_pipeline_schedule_play(project, resp_project_pipeline_schedule)
5690 assert description == sched .description
5791 assert 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 ()
6096 assert play_result is not None
6197 assert "message" in play_result
6298 assert 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"
0 commit comments