Skip to content

Commit 9f04560

Browse files
committed
ci: add a test for creating and triggering pipeline schedule
1 parent 07b9988 commit 9f04560

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

gitlab/tests/objects/test_projects.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,45 @@ def resp_get_active_services(url, request):
257257
return response(200, content, headers, None, 5, request)
258258

259259

260+
@urlmatch(
261+
scheme="http", netloc="localhost", path="/api/v4/projects/1/pipeline_schedules$", method="post",
262+
)
263+
def resp_create_project_pipeline_schedule(url, request):
264+
"""Mock for creating project pipeline Schedules POST response."""
265+
content = """{
266+
"id": 14,
267+
"description": "Build packages",
268+
"ref": "master",
269+
"cron": "0 1 * * 5",
270+
"cron_timezone": "UTC",
271+
"next_run_at": "2017-05-26T01:00:00.000Z",
272+
"active": true,
273+
"created_at": "2017-05-19T13:43:08.169Z",
274+
"updated_at": "2017-05-19T13:43:08.169Z",
275+
"last_pipeline": null,
276+
"owner": {
277+
"name": "Administrator",
278+
"username": "root",
279+
"id": 1,
280+
"state": "active",
281+
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
282+
"web_url": "https://gitlab.example.com/root"
283+
}
284+
}"""
285+
content = content.encode("utf-8")
286+
return response(200, content, headers, None, 5, request)
287+
288+
289+
@urlmatch(
290+
scheme="http", netloc="localhost", path="/api/v4/projects/1/pipeline_schedules/14/play", method="post",
291+
)
292+
def resp_play_project_pipeline_schedule(url, request):
293+
"""Mock for playing a project pipeline schedule POST response."""
294+
content = """{"message": "201 Created"}"""
295+
content = content.encode("utf-8")
296+
return response(200, content, headers, None, 5, request)
297+
298+
260299
class TestProject(unittest.TestCase):
261300
"""Base class for GitLab Project tests."""
262301

@@ -480,3 +519,25 @@ def test_update_service(self):
480519
service.issues_events = True
481520
service.save()
482521
self.assertEqual(service.issues_events, True)
522+
523+
524+
class TestProjectPipelineSchedule(TestProject):
525+
526+
@with_httmock(resp_create_project_pipeline_schedule,
527+
resp_play_project_pipeline_schedule)
528+
def test_project_pipeline_schedule_play(self):
529+
description = 'Build packages'
530+
cronline = '0 1 * * 5'
531+
sched = self.project.pipelineschedules.create({
532+
'ref': 'master',
533+
'description': description,
534+
'cron': cronline})
535+
self.assertIsNotNone(sched)
536+
self.assertEqual(description, sched.description)
537+
self.assertEqual(cronline, sched.cron)
538+
539+
play_result = sched.play()
540+
self.assertIsNotNone(play_result)
541+
self.assertIn('message', play_result)
542+
self.assertEqual('201 Created', play_result['message'])
543+

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy