Skip to content

feat: add pipeline test report support #1249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions docs/gl_objects/pipelines_and_jobs.rst
Original file line number Diff line number Diff line change
Expand Up @@ -326,3 +326,26 @@ Examples
List bridges for the pipeline::

bridges = pipeline.bridges.list()

Pipeline test report
====================

Get a pipeline's complete test report.

Reference
---------

* v4 API

+ :class:`gitlab.v4.objects.ProjectPipelineTestReport`
+ :class:`gitlab.v4.objects.ProjectPipelineTestReportManager`
+ :attr:`gitlab.v4.objects.ProjectPipeline.test_report`

* GitLab API: https://docs.gitlab.com/ee/api/pipelines.html#get-a-pipelines-test-report

Examples
--------

Get the test report for a pipeline::

test_report = pipeline.test_report.get()
14 changes: 14 additions & 0 deletions gitlab/v4/objects/pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
CreateMixin,
CRUDMixin,
DeleteMixin,
GetWithoutIdMixin,
ListMixin,
ObjectDeleteMixin,
RefreshMixin,
Expand All @@ -26,6 +27,8 @@
"ProjectPipelineScheduleVariableManager",
"ProjectPipelineSchedule",
"ProjectPipelineScheduleManager",
"ProjectPipelineTestReport",
"ProjectPipelineTestReportManager",
]


Expand All @@ -34,6 +37,7 @@ class ProjectPipeline(RefreshMixin, ObjectDeleteMixin, RESTObject):
("jobs", "ProjectPipelineJobManager"),
("bridges", "ProjectPipelineBridgeManager"),
("variables", "ProjectPipelineVariableManager"),
("test_report", "ProjectPipelineTestReportManager"),
)

@cli.register_custom_action("ProjectPipeline")
Expand Down Expand Up @@ -201,3 +205,13 @@ class ProjectPipelineScheduleManager(CRUDMixin, RESTManager):
_update_attrs = RequiredOptional(
optional=("description", "ref", "cron", "cron_timezone", "active"),
)


class ProjectPipelineTestReport(RESTObject):
_id_attr = None


class ProjectPipelineTestReportManager(GetWithoutIdMixin, RESTManager):
_path = "/projects/%(project_id)s/pipelines/%(pipeline_id)s/test_report"
_obj_cls = ProjectPipelineTestReport
_from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}
54 changes: 53 additions & 1 deletion tests/unit/objects/test_pipelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
import responses

from gitlab.v4.objects import ProjectPipeline
from gitlab.v4.objects import ProjectPipeline, ProjectPipelineTestReport

pipeline_content = {
"id": 46,
Expand Down Expand Up @@ -35,6 +35,37 @@
}


test_report_content = {
"total_time": 5,
"total_count": 1,
"success_count": 1,
"failed_count": 0,
"skipped_count": 0,
"error_count": 0,
"test_suites": [
{
"name": "Secure",
"total_time": 5,
"total_count": 1,
"success_count": 1,
"failed_count": 0,
"skipped_count": 0,
"error_count": 0,
"test_cases": [
{
"status": "success",
"name": "Security Reports can create an auto-remediation MR",
"classname": "vulnerability_management_spec",
"execution_time": 5,
"system_output": None,
"stack_trace": None,
}
],
}
],
}


@pytest.fixture
def resp_get_pipeline():
with responses.RequestsMock() as rsps:
Expand Down Expand Up @@ -74,6 +105,19 @@ def resp_retry_pipeline():
yield rsps


@pytest.fixture
def resp_get_pipeline_test_report():
with responses.RequestsMock() as rsps:
rsps.add(
method=responses.GET,
url="http://localhost/api/v4/projects/1/pipelines/1/test_report",
json=test_report_content,
content_type="application/json",
status=200,
)
yield rsps


def test_get_project_pipeline(project, resp_get_pipeline):
pipeline = project.pipelines.get(1)
assert isinstance(pipeline, ProjectPipeline)
Expand All @@ -92,3 +136,11 @@ def test_retry_project_pipeline(project, resp_retry_pipeline):

output = pipeline.retry()
assert output["ref"] == "master"


def test_get_project_pipeline_test_report(project, resp_get_pipeline_test_report):
pipeline = project.pipelines.get(1, lazy=True)
test_report = pipeline.test_report.get()
assert isinstance(test_report, ProjectPipelineTestReport)
assert test_report.total_time == 5
assert test_report.test_suites[0]["name"] == "Secure"