Skip to content

Commit

Permalink
feat(api): add issue details tests documentation
Browse files Browse the repository at this point in the history
Part of #86
Closes #818
  • Loading branch information
murilx committed Jan 30, 2025
1 parent 6fa1d2f commit e338096
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 4 deletions.
13 changes: 13 additions & 0 deletions backend/kernelCI_app/typeModels/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,21 @@ class IssueBuildItem(BaseModel):
log_url: Optional[str]


class IssueTestItem(BaseModel):
id: str
status: Optional[str]
duration: Optional[Union[int, float]]
path: Optional[str]
start_time: Optional[Union[datetime, str]]
environment_compatible: Optional[Union[str, List[str]]]


class IssuesBuildResponse(RootModel):
root: List[IssueBuildItem]


class IssuesTestsResponse(RootModel):
root: List[IssueTestItem]


type IssueDict = Dict[Tuple[str, str], Issue]
21 changes: 17 additions & 4 deletions backend/kernelCI_app/views/issueDetailsTestsView.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
from http import HTTPStatus
from typing import Dict, Optional
from django.http import JsonResponse
from django.views import View
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.models import Incidents
from kernelCI_app.typeModels.issues import IssueDetailsPathParameters
from kernelCI_app.typeModels.issues import (
IssueDetailsPathParameters,
IssuesTestsResponse,
)
from drf_spectacular.utils import extend_schema
from rest_framework.views import APIView
from pydantic import ValidationError


class IssueDetailsTests(View):
class IssueDetailsTests(APIView):
def _fetch_incidents(self, *, issue_id: str, version: int) -> Optional[Dict]:
fields = [
"test__id",
Expand All @@ -35,6 +39,7 @@ def _fetch_incidents(self, *, issue_id: str, version: int) -> Optional[Dict]:
for test in tests
]

@extend_schema(responses=IssuesTestsResponse)
def get(
self, _request, issue_id: Optional[str], version: Optional[str]
) -> JsonResponse:
Expand All @@ -54,4 +59,12 @@ def get(
error_message="No tests found for this issue", status_code=HTTPStatus.OK
)

return JsonResponse(tests_data, safe=False)
try:
valid_response = IssuesTestsResponse(tests_data)
except ValidationError as e:
return create_error_response(
error_message=e.errors(),
status_code=HTTPStatus.INTERNAL_SERVER_ERROR,
)

return JsonResponse(valid_response.model_dump(), safe=False)
77 changes: 77 additions & 0 deletions backend/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,33 @@ paths:
schema:
$ref: '#/components/schemas/IssuesBuildResponse'
description: ''
/api/issue/{issue_id}/version/{version}/tests:
get:
operationId: issue_version_tests_retrieve
parameters:
- in: path
name: issue_id
schema:
type: string
required: true
- in: path
name: version
schema:
type: string
required: true
tags:
- issue
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/IssuesTestsResponse'
description: ''
/api/log-downloader/:
get:
operationId: log_downloader_retrieve
Expand Down Expand Up @@ -1201,11 +1228,61 @@ components:
- log_url
title: IssueBuildItem
type: object
IssueTestItem:
properties:
id:
title: Id
type: string
status:
anyOf:
- type: string
- type: 'null'
title: Status
duration:
anyOf:
- type: integer
- type: number
- type: 'null'
title: Duration
path:
anyOf:
- type: string
- type: 'null'
title: Path
start_time:
anyOf:
- format: date-time
type: string
- type: string
- type: 'null'
title: Start Time
environment_compatible:
anyOf:
- type: string
- items:
type: string
type: array
- type: 'null'
title: Environment Compatible
required:
- id
- status
- duration
- path
- start_time
- environment_compatible
title: IssueTestItem
type: object
IssuesBuildResponse:
items:
$ref: '#/components/schemas/IssueBuildItem'
title: IssuesBuildResponse
type: array
IssuesTestsResponse:
items:
$ref: '#/components/schemas/IssueTestItem'
title: IssuesTestsResponse
type: array
Misc:
properties:
platform:
Expand Down

0 comments on commit e338096

Please sign in to comment.