summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Zorn <christopherzo@zillowgroup.com>2020-04-21 09:14:13 -0700
committerChristopher Zorn <christopherzo@zillowgroup.com>2020-04-21 09:14:13 -0700
commit9f04560e59f372f80ac199aeee16378d8f80610c (patch)
tree5e0a15936feb1e70fa20a02d0ef805f7f5fdd30a
parent07b99881dfa6efa9665245647460e99846ccd341 (diff)
downloadgitlab-9f04560e59f372f80ac199aeee16378d8f80610c.tar.gz
ci: add a test for creating and triggering pipeline schedule
-rw-r--r--gitlab/tests/objects/test_projects.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_projects.py b/gitlab/tests/objects/test_projects.py
index 6a2840a..9f74bdb 100644
--- a/gitlab/tests/objects/test_projects.py
+++ b/gitlab/tests/objects/test_projects.py
@@ -257,6 +257,45 @@ def resp_get_active_services(url, request):
return response(200, content, headers, None, 5, request)
+@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)
+
+
class TestProject(unittest.TestCase):
"""Base class for GitLab Project tests."""
@@ -480,3 +519,25 @@ class TestProjectServices(TestProject):
service.issues_events = True
service.save()
self.assertEqual(service.issues_events, True)
+
+
+class TestProjectPipelineSchedule(TestProject):
+
+ @with_httmock(resp_create_project_pipeline_schedule,
+ resp_play_project_pipeline_schedule)
+ def test_project_pipeline_schedule_play(self):
+ description = 'Build packages'
+ cronline = '0 1 * * 5'
+ sched = self.project.pipelineschedules.create({
+ 'ref': 'master',
+ 'description': description,
+ 'cron': cronline})
+ self.assertIsNotNone(sched)
+ self.assertEqual(description, sched.description)
+ self.assertEqual(cronline, sched.cron)
+
+ play_result = sched.play()
+ self.assertIsNotNone(play_result)
+ self.assertIn('message', play_result)
+ self.assertEqual('201 Created', play_result['message'])
+