summaryrefslogtreecommitdiff
path: root/gitlab/tests/objects
diff options
context:
space:
mode:
authorNejc Habjan <hab.nejc@gmail.com>2021-05-02 19:48:51 +0200
committerNejc Habjan <hab.nejc@gmail.com>2021-05-02 19:48:51 +0200
commit9fed06116bfe5df79e6ac5be86ae61017f9a2f57 (patch)
tree63f329a4f72cf9ace085a8b585324b2fbb9550bb /gitlab/tests/objects
parentb563cdc1a6cd585647fc53722081dceb6f7b4466 (diff)
downloadgitlab-9fed06116bfe5df79e6ac5be86ae61017f9a2f57.tar.gz
fix(objects): return server data in cancel/retry methods
Diffstat (limited to 'gitlab/tests/objects')
-rw-r--r--gitlab/tests/objects/test_jobs.py97
-rw-r--r--gitlab/tests/objects/test_pipelines.py95
2 files changed, 192 insertions, 0 deletions
diff --git a/gitlab/tests/objects/test_jobs.py b/gitlab/tests/objects/test_jobs.py
new file mode 100644
index 0000000..ff468ef
--- /dev/null
+++ b/gitlab/tests/objects/test_jobs.py
@@ -0,0 +1,97 @@
+"""
+GitLab API: https://docs.gitlab.com/ee/api/jobs.html
+"""
+import pytest
+import responses
+
+from gitlab.v4.objects import ProjectJob
+
+
+job_content = {
+ "commit": {
+ "author_email": "admin@example.com",
+ "author_name": "Administrator",
+ },
+ "coverage": None,
+ "allow_failure": False,
+ "created_at": "2015-12-24T15:51:21.880Z",
+ "started_at": "2015-12-24T17:54:30.733Z",
+ "finished_at": "2015-12-24T17:54:31.198Z",
+ "duration": 0.465,
+ "queued_duration": 0.010,
+ "artifacts_expire_at": "2016-01-23T17:54:31.198Z",
+ "tag_list": ["docker runner", "macos-10.15"],
+ "id": 1,
+ "name": "rubocop",
+ "pipeline": {
+ "id": 1,
+ "project_id": 1,
+ },
+ "ref": "master",
+ "artifacts": [],
+ "runner": None,
+ "stage": "test",
+ "status": "failed",
+ "tag": False,
+ "web_url": "https://example.com/foo/bar/-/jobs/1",
+ "user": {"id": 1},
+}
+
+
+@pytest.fixture
+def resp_get_job():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/jobs/1",
+ json=job_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_cancel_job():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/jobs/1/cancel",
+ json=job_content,
+ content_type="application/json",
+ status=201,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_retry_job():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/jobs/1/retry",
+ json=job_content,
+ content_type="application/json",
+ status=201,
+ )
+ yield rsps
+
+
+def test_get_project_job(project, resp_get_job):
+ job = project.jobs.get(1)
+ assert isinstance(job, ProjectJob)
+ assert job.ref == "master"
+
+
+def test_cancel_project_job(project, resp_cancel_job):
+ job = project.jobs.get(1, lazy=True)
+
+ output = job.cancel()
+ assert output["ref"] == "master"
+
+
+def test_retry_project_job(project, resp_retry_job):
+ job = project.jobs.get(1, lazy=True)
+
+ output = job.retry()
+ assert output["ref"] == "master"
diff --git a/gitlab/tests/objects/test_pipelines.py b/gitlab/tests/objects/test_pipelines.py
new file mode 100644
index 0000000..f54aa7d
--- /dev/null
+++ b/gitlab/tests/objects/test_pipelines.py
@@ -0,0 +1,95 @@
+"""
+GitLab API: https://docs.gitlab.com/ee/api/pipelines.html
+"""
+import pytest
+import responses
+
+from gitlab.v4.objects import ProjectPipeline
+
+
+pipeline_content = {
+ "id": 46,
+ "project_id": 1,
+ "status": "pending",
+ "ref": "master",
+ "sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
+ "before_sha": "a91957a858320c0e17f3a0eca7cfacbff50ea29a",
+ "tag": False,
+ "yaml_errors": None,
+ "user": {
+ "name": "Administrator",
+ "username": "root",
+ "id": 1,
+ "state": "active",
+ "avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
+ "web_url": "http://localhost:3000/root",
+ },
+ "created_at": "2016-08-11T11:28:34.085Z",
+ "updated_at": "2016-08-11T11:32:35.169Z",
+ "started_at": None,
+ "finished_at": "2016-08-11T11:32:35.145Z",
+ "committed_at": None,
+ "duration": None,
+ "queued_duration": 0.010,
+ "coverage": None,
+ "web_url": "https://example.com/foo/bar/pipelines/46",
+}
+
+
+@pytest.fixture
+def resp_get_pipeline():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.GET,
+ url="http://localhost/api/v4/projects/1/pipelines/1",
+ json=pipeline_content,
+ content_type="application/json",
+ status=200,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_cancel_pipeline():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/pipelines/1/cancel",
+ json=pipeline_content,
+ content_type="application/json",
+ status=201,
+ )
+ yield rsps
+
+
+@pytest.fixture
+def resp_retry_pipeline():
+ with responses.RequestsMock() as rsps:
+ rsps.add(
+ method=responses.POST,
+ url="http://localhost/api/v4/projects/1/pipelines/1/retry",
+ json=pipeline_content,
+ content_type="application/json",
+ status=201,
+ )
+ yield rsps
+
+
+def test_get_project_pipeline(project, resp_get_pipeline):
+ pipeline = project.pipelines.get(1)
+ assert isinstance(pipeline, ProjectPipeline)
+ assert pipeline.ref == "master"
+
+
+def test_cancel_project_pipeline(project, resp_cancel_pipeline):
+ pipeline = project.pipelines.get(1, lazy=True)
+
+ output = pipeline.cancel()
+ assert output["ref"] == "master"
+
+
+def test_retry_project_pipeline(project, resp_retry_pipeline):
+ pipeline = project.pipelines.get(1, lazy=True)
+
+ output = pipeline.retry()
+ assert output["ref"] == "master"