summaryrefslogtreecommitdiff
path: root/tests/unit
diff options
context:
space:
mode:
authorNejc Habjan <nejc.habjan@siemens.com>2022-12-06 01:15:15 +0100
committerNejc Habjan <hab.nejc@gmail.com>2022-12-11 05:44:44 +0100
commitc7cf0d1f172c214a11b30622fbccef57d9c86e93 (patch)
tree16d568e9f529abdb982732fb501174ac7cf2339e /tests/unit
parent9a9a6a98007df2992286a721507b02c48800bfed (diff)
downloadgitlab-c7cf0d1f172c214a11b30622fbccef57d9c86e93.tar.gz
test(unit): expand tests for pipeline schedules
Diffstat (limited to 'tests/unit')
-rw-r--r--tests/unit/conftest.py5
-rw-r--r--tests/unit/objects/test_pipeline_schedules.py53
2 files changed, 54 insertions, 4 deletions
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index 5d3bfd5..1b52d86 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -90,5 +90,10 @@ def release(project, tag_name):
@pytest.fixture
+def schedule(project):
+ return project.pipelineschedules.get(1, lazy=True)
+
+
+@pytest.fixture
def user(gl):
return gl.users.get(1, lazy=True)
diff --git a/tests/unit/objects/test_pipeline_schedules.py b/tests/unit/objects/test_pipeline_schedules.py
index f038756..8b8dab8 100644
--- a/tests/unit/objects/test_pipeline_schedules.py
+++ b/tests/unit/objects/test_pipeline_schedules.py
@@ -4,9 +4,24 @@ GitLab API: https://docs.gitlab.com/ce/api/pipeline_schedules.html
import pytest
import responses
+from gitlab.v4.objects import ProjectPipelineSchedulePipeline
+
+pipeline_content = {
+ "id": 48,
+ "iid": 13,
+ "project_id": 29,
+ "status": "pending",
+ "source": "scheduled",
+ "ref": "new-pipeline",
+ "sha": "eb94b618fb5865b26e80fdd8ae531b7a63ad851a",
+ "web_url": "https://example.com/foo/bar/pipelines/48",
+ "created_at": "2016-08-12T10:06:04.561Z",
+ "updated_at": "2016-08-12T10:09:56.223Z",
+}
+
@pytest.fixture
-def resp_project_pipeline_schedule(created_content):
+def resp_create_pipeline_schedule():
content = {
"id": 14,
"description": "Build packages",
@@ -36,9 +51,15 @@ def resp_project_pipeline_schedule(created_content):
content_type="application/json",
status=200,
)
+ yield rsps
+
+
+@pytest.fixture
+def resp_play_pipeline_schedule(created_content):
+ with responses.RequestsMock() as rsps:
rsps.add(
method=responses.POST,
- url="http://localhost/api/v4/projects/1/pipeline_schedules/14/play",
+ url="http://localhost/api/v4/projects/1/pipeline_schedules/1/play",
json=created_content,
content_type="application/json",
status=201,
@@ -46,7 +67,20 @@ def resp_project_pipeline_schedule(created_content):
yield rsps
-def test_project_pipeline_schedule_play(project, resp_project_pipeline_schedule):
+@pytest.fixture
+def resp_list_schedule_pipelines():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/pipeline_schedules/1/pipelines",
+ json=[pipeline_content],
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+def test_create_project_pipeline_schedule(project, resp_create_pipeline_schedule):
description = "Build packages"
cronline = "0 1 * * 5"
sched = project.pipelineschedules.create(
@@ -56,7 +90,18 @@ def test_project_pipeline_schedule_play(project, resp_project_pipeline_schedule)
assert description == sched.description
assert cronline == sched.cron
- play_result = sched.play()
+
+def test_play_project_pipeline_schedule(schedule, resp_play_pipeline_schedule):
+ play_result = schedule.play()
assert play_result is not None
assert "message" in play_result
assert play_result["message"] == "201 Created"
+
+
+def test_list_project_pipeline_schedule_pipelines(
+ schedule, resp_list_schedule_pipelines
+):
+ pipelines = schedule.pipelines.list()
+ assert isinstance(pipelines, list)
+ assert isinstance(pipelines[0], ProjectPipelineSchedulePipeline)
+ assert pipelines[0].source == "scheduled"