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 37596d7 commit 6fa1d2f
Show file tree
Hide file tree
Showing 4 changed files with 123 additions and 8 deletions.
22 changes: 22 additions & 0 deletions backend/kernelCI_app/typeModels/buildDetails.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from typing import List
from pydantic import BaseModel, RootModel

from kernelCI_app.typeModels.commonDetails import BuildHistoryItem
from kernelCI_app.typeModels.databases import (
TOrigin,
Expand All @@ -12,6 +15,12 @@
TBuild__log_excerpt,
TBuild__input_files,
TBuild__output_files,
TTest__id,
TTest__status,
TTest__duration,
TTest__path,
TTest__start_time,
TTest__environment_compatible,
)


Expand All @@ -28,3 +37,16 @@ class BuildDetailsResponse(BuildHistoryItem):
log_excerpt: TBuild__log_excerpt
input_files: TBuild__input_files
output_files: TBuild__output_files


class BuildTestItem(BaseModel):
id: TTest__id
status: TTest__status
duration: TTest__duration
path: TTest__path
start_time: TTest__start_time
environment_compatible: TTest__environment_compatible


class BuildTestsResponse(RootModel):
root: List[BuildTestItem]
7 changes: 7 additions & 0 deletions backend/kernelCI_app/typeModels/databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@
type TBuild__input_files = Optional[List[Dict[str, Any]]]
type TBuild__output_files = Optional[List[Dict[str, Any]]]

type TTest__id = str
type TTest__status = Optional[str]
type TTest__duration = Optional[float]
type TTest__path = Optional[str]
type TTest__start_time = Optional[datetime]
type TTest__environment_compatible = Optional[List[str]]


class Issues(BaseModel):
field_timestamp: Optional[datetime] = Field(None, alias="_timestamp")
Expand Down
27 changes: 19 additions & 8 deletions backend/kernelCI_app/views/buildTestsView.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
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 rest_framework.response import Response
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"
)

if not result:
return create_error_response(
error_message="No tests found for this build",
status_code=HTTPStatus.OK,
return Response(
data={"error": "No tests found for this build"},
status=HTTPStatus.OK,
)

return JsonResponse(list(result), safe=False)
try:
valid_response = BuildTestsResponse(result)
except ValidationError as e:
return Response(
data={"error": e.errors()},
status=HTTPStatus.INTERNAL_SERVER_ERROR,
)

return Response(valid_response.model_dump())
75 changes: 75 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 @@ -820,6 +842,34 @@ components:
- unknown_issues
title: BuildSummary
type: object
BuildTestItem:
properties:
id:
$ref: '#/components/schemas/TTest__id'
status:
$ref: '#/components/schemas/TTest__status'
duration:
$ref: '#/components/schemas/TTest__duration'
path:
$ref: '#/components/schemas/TTest__path'
start_time:
$ref: '#/components/schemas/TTest__start_time'
environment_compatible:
$ref: '#/components/schemas/TTest__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 Expand Up @@ -1241,6 +1291,31 @@ components:
- type: 'null'
TOrigin:
type: string
TTest__duration:
anyOf:
- type: number
- type: 'null'
TTest__environment_compatible:
anyOf:
- items:
type: string
type: array
- type: 'null'
TTest__id:
type: string
TTest__path:
anyOf:
- type: string
- type: 'null'
TTest__start_time:
anyOf:
- format: date-time
type: string
- type: 'null'
TTest__status:
anyOf:
- type: string
- type: 'null'
TestArchSummaryItem:
properties:
arch:
Expand Down

0 comments on commit 6fa1d2f

Please sign in to comment.