-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathhardwareView.py
More file actions
96 lines (86 loc) · 3.51 KB
/
Copy pathhardwareView.py
File metadata and controls
96 lines (86 loc) · 3.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from http import HTTPStatus
from drf_spectacular.utils import extend_schema
from pydantic import ValidationError
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.views import APIView
from kernelCI_app.constants.localization import ClientStrings
from kernelCI_app.helpers.errorHandling import (
create_api_error_response,
)
from kernelCI_app.queries.hardware import get_hardware_listing_data
from kernelCI_app.typeModels.hardwareListing import (
HardwareItem,
HardwareListingResponse,
HardwareQueryParams,
HardwareQueryParamsDocumentationOnly,
)
class HardwareView(APIView):
def _sanitize_records(self, hardwares_raw: list[tuple]) -> list[HardwareItem]:
hardwares = []
for hardware in hardwares_raw:
hardwares.append(
HardwareItem(
platform=hardware[0],
hardware=hardware[1],
build_status_summary={
"PASS": hardware[2],
"FAIL": hardware[3],
"NULL": hardware[4],
"ERROR": hardware[5],
"MISS": hardware[6],
"DONE": hardware[7],
"SKIP": hardware[8],
},
boot_status_summary={
"PASS": hardware[9],
"FAIL": hardware[10],
"NULL": hardware[11],
"ERROR": hardware[12],
"MISS": hardware[13],
"DONE": hardware[14],
"SKIP": hardware[15],
},
test_status_summary={
"PASS": hardware[16],
"FAIL": hardware[17],
"NULL": hardware[18],
"ERROR": hardware[19],
"MISS": hardware[20],
"DONE": hardware[21],
"SKIP": hardware[22],
},
)
)
return hardwares
@extend_schema(
parameters=[HardwareQueryParamsDocumentationOnly],
responses=HardwareListingResponse,
)
def get(self, request: Request):
try:
query_params = HardwareQueryParams(
start_date=request.GET.get("startTimestampInSeconds"),
end_date=request.GET.get("endTimestampInSeconds"),
origin=request.GET.get("origin"),
commits_list=request.GET.get("commitsList"),
)
except ValidationError as e:
return Response(data=e.json(), status=HTTPStatus.BAD_REQUEST)
hardwares_raw = get_hardware_listing_data(
origin=query_params.origin,
start_date=query_params.start_date,
end_date=query_params.end_date,
commits_list=query_params.commits_list,
)
try:
sanitized_records = self._sanitize_records(hardwares_raw=hardwares_raw)
result = HardwareListingResponse(hardware=sanitized_records)
if len(result.hardware) < 1:
return create_api_error_response(
error_message=ClientStrings.NO_HARDWARE_FOUND,
status_code=HTTPStatus.OK,
)
except ValidationError as e:
return Response(data=e.json(), status=HTTPStatus.INTERNAL_SERVER_ERROR)
return Response(data=result.model_dump(), status=HTTPStatus.OK)