-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(api): add build tests view documentation
- Loading branch information
Showing
4 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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): | ||
def get(self, request, build_id): | ||
class BuildTests(APIView): | ||
@extend_schema(responses=BuildTestsResponse) | ||
def get(self, request, build_id: str) -> Response: | ||
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()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters