Skip to content

Commit

Permalink
feat(api): add build tests view documentation
Browse files Browse the repository at this point in the history
Part of #86
Closes #815
  • Loading branch information
murilx committed Jan 30, 2025
1 parent 8e8aa9e commit b977acc
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 4 deletions.
17 changes: 16 additions & 1 deletion backend/kernelCI_app/typeModels/buildDetails.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from typing import Optional, List, Dict, Any
from datetime import datetime
from typing import Optional, List, Dict, Any, Union
from pydantic import BaseModel, RootModel

from kernelCI_app.typeModels.commonDetails import BuildHistoryItem

Expand All @@ -16,3 +18,16 @@ class BuildDetailsResponse(BuildHistoryItem):
log_excerpt: Optional[str]
input_files: Optional[List[Dict[str, Any]]]
output_files: Optional[List[Dict[str, Any]]]


class BuildTestItem(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 BuildTestsResponse(RootModel):
root: List[BuildTestItem]
18 changes: 15 additions & 3 deletions backend/kernelCI_app/views/buildTestsView.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from django.http import JsonResponse
from django.views import View
from http import HTTPStatus
from kernelCI_app.helpers.errorHandling import create_error_response
from kernelCI_app.typeModels.buildDetails import BuildTestsResponse
from kernelCI_app.models import Tests
from drf_spectacular.utils import extend_schema
from rest_framework.views import APIView
from pydantic import ValidationError


class BuildTests(View):
class BuildTests(APIView):
@extend_schema(responses=BuildTestsResponse)
def get(self, request, build_id):
result = Tests.objects.filter(build_id=build_id).values(
"id", "duration", "status", "path", "start_time", "environment_compatible"
Expand All @@ -17,4 +21,12 @@ def get(self, request, build_id):
status_code=HTTPStatus.OK,
)

return JsonResponse(list(result), safe=False)
try:
valid_response = BuildTestsResponse(result)
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)
72 changes: 72 additions & 0 deletions backend/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,28 @@ paths:
schema:
$ref: '#/components/schemas/BuildDetailsResponse'
description: ''
/api/build/{build_id}/tests:
get:
operationId: build_tests_retrieve
parameters:
- in: path
name: build_id
schema:
type: string
required: true
tags:
- build
security:
- cookieAuth: []
- basicAuth: []
- {}
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/BuildTestsResponse'
description: ''
/api/hardware/{hardware_id}:
post:
operationId: hardware_create
Expand Down Expand Up @@ -859,6 +881,56 @@ components:
- unknown_issues
title: BuildSummary
type: object
BuildTestItem:
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: BuildTestItem
type: object
BuildTestsResponse:
items:
$ref: '#/components/schemas/BuildTestItem'
title: BuildTestsResponse
type: array
CommonDetailsBootsResponse:
properties:
boots:
Expand Down

0 comments on commit b977acc

Please sign in to comment.