Skip to content

Commit fb7174e

Browse files
authored
Merge pull request #1249 from rmonat/master
feat: add pipeline test report support
2 parents 861d3d2 + ee9f96e commit fb7174e

File tree

3 files changed

+90
-1
lines changed

3 files changed

+90
-1
lines changed

docs/gl_objects/pipelines_and_jobs.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,3 +326,26 @@ Examples
326326
List bridges for the pipeline::
327327

328328
bridges = pipeline.bridges.list()
329+
330+
Pipeline test report
331+
====================
332+
333+
Get a pipeline's complete test report.
334+
335+
Reference
336+
---------
337+
338+
* v4 API
339+
340+
+ :class:`gitlab.v4.objects.ProjectPipelineTestReport`
341+
+ :class:`gitlab.v4.objects.ProjectPipelineTestReportManager`
342+
+ :attr:`gitlab.v4.objects.ProjectPipeline.test_report`
343+
344+
* GitLab API: https://docs.gitlab.com/ee/api/pipelines.html#get-a-pipelines-test-report
345+
346+
Examples
347+
--------
348+
349+
Get the test report for a pipeline::
350+
351+
test_report = pipeline.test_report.get()

gitlab/v4/objects/pipelines.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
CreateMixin,
66
CRUDMixin,
77
DeleteMixin,
8+
GetWithoutIdMixin,
89
ListMixin,
910
ObjectDeleteMixin,
1011
RefreshMixin,
@@ -26,6 +27,8 @@
2627
"ProjectPipelineScheduleVariableManager",
2728
"ProjectPipelineSchedule",
2829
"ProjectPipelineScheduleManager",
30+
"ProjectPipelineTestReport",
31+
"ProjectPipelineTestReportManager",
2932
]
3033

3134

@@ -34,6 +37,7 @@ class ProjectPipeline(RefreshMixin, ObjectDeleteMixin, RESTObject):
3437
("jobs", "ProjectPipelineJobManager"),
3538
("bridges", "ProjectPipelineBridgeManager"),
3639
("variables", "ProjectPipelineVariableManager"),
40+
("test_report", "ProjectPipelineTestReportManager"),
3741
)
3842

3943
@cli.register_custom_action("ProjectPipeline")
@@ -201,3 +205,13 @@ class ProjectPipelineScheduleManager(CRUDMixin, RESTManager):
201205
_update_attrs = RequiredOptional(
202206
optional=("description", "ref", "cron", "cron_timezone", "active"),
203207
)
208+
209+
210+
class ProjectPipelineTestReport(RESTObject):
211+
_id_attr = None
212+
213+
214+
class ProjectPipelineTestReportManager(GetWithoutIdMixin, RESTManager):
215+
_path = "/projects/%(project_id)s/pipelines/%(pipeline_id)s/test_report"
216+
_obj_cls = ProjectPipelineTestReport
217+
_from_parent_attrs = {"project_id": "project_id", "pipeline_id": "id"}

tests/unit/objects/test_pipelines.py

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import pytest
55
import responses
66

7-
from gitlab.v4.objects import ProjectPipeline
7+
from gitlab.v4.objects import ProjectPipeline, ProjectPipelineTestReport
88

99
pipeline_content = {
1010
"id": 46,
@@ -35,6 +35,37 @@
3535
}
3636

3737

38+
test_report_content = {
39+
"total_time": 5,
40+
"total_count": 1,
41+
"success_count": 1,
42+
"failed_count": 0,
43+
"skipped_count": 0,
44+
"error_count": 0,
45+
"test_suites": [
46+
{
47+
"name": "Secure",
48+
"total_time": 5,
49+
"total_count": 1,
50+
"success_count": 1,
51+
"failed_count": 0,
52+
"skipped_count": 0,
53+
"error_count": 0,
54+
"test_cases": [
55+
{
56+
"status": "success",
57+
"name": "Security Reports can create an auto-remediation MR",
58+
"classname": "vulnerability_management_spec",
59+
"execution_time": 5,
60+
"system_output": None,
61+
"stack_trace": None,
62+
}
63+
],
64+
}
65+
],
66+
}
67+
68+
3869
@pytest.fixture
3970
def resp_get_pipeline():
4071
with responses.RequestsMock() as rsps:
@@ -74,6 +105,19 @@ def resp_retry_pipeline():
74105
yield rsps
75106

76107

108+
@pytest.fixture
109+
def resp_get_pipeline_test_report():
110+
with responses.RequestsMock() as rsps:
111+
rsps.add(
112+
method=responses.GET,
113+
url="http://localhost/api/v4/projects/1/pipelines/1/test_report",
114+
json=test_report_content,
115+
content_type="application/json",
116+
status=200,
117+
)
118+
yield rsps
119+
120+
77121
def test_get_project_pipeline(project, resp_get_pipeline):
78122
pipeline = project.pipelines.get(1)
79123
assert isinstance(pipeline, ProjectPipeline)
@@ -92,3 +136,11 @@ def test_retry_project_pipeline(project, resp_retry_pipeline):
92136

93137
output = pipeline.retry()
94138
assert output["ref"] == "master"
139+
140+
141+
def test_get_project_pipeline_test_report(project, resp_get_pipeline_test_report):
142+
pipeline = project.pipelines.get(1, lazy=True)
143+
test_report = pipeline.test_report.get()
144+
assert isinstance(test_report, ProjectPipelineTestReport)
145+
assert test_report.total_time == 5
146+
assert test_report.test_suites[0]["name"] == "Secure"

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