Skip to content

Commit

Permalink
fix: add error docs, refactor test case
Browse files Browse the repository at this point in the history
  • Loading branch information
jason810496 committed Oct 29, 2024
1 parent 9392ebe commit 5faa9be
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 23 deletions.
18 changes: 18 additions & 0 deletions airflow/api_fastapi/core_api/openapi/v1-generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1526,6 +1526,24 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/EventLogResponse'
'401':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Unauthorized
'403':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Forbidden
'404':
content:
application/json:
schema:
$ref: '#/components/schemas/HTTPExceptionResponse'
description: Not Found
'422':
description: Validation Error
content:
Expand Down
6 changes: 5 additions & 1 deletion airflow/api_fastapi/core_api/routes/public/event_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
get_session,
)
from airflow.api_fastapi.common.router import AirflowRouter
from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.serializers.event_logs import (
EventLogResponse,
)
Expand All @@ -33,7 +34,10 @@
event_logs_router = AirflowRouter(tags=["Event Log"], prefix="/eventLogs")


@event_logs_router.get("/{event_log_id}")
@event_logs_router.get(
"/{event_log_id}",
responses=create_openapi_http_exception_doc([401, 403, 404]),
)
async def get_event_log(
event_log_id: int,
session: Annotated[Session, Depends(get_session)],
Expand Down
3 changes: 3 additions & 0 deletions airflow/ui/openapi-gen/requests/services.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -915,6 +915,9 @@ export class EventLogService {
event_log_id: data.eventLogId,
},
errors: {
401: "Unauthorized",
403: "Forbidden",
404: "Not Found",
422: "Validation Error",
},
});
Expand Down
12 changes: 12 additions & 0 deletions airflow/ui/openapi-gen/requests/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,18 @@ export type $OpenApiTs = {
* Successful Response
*/
200: EventLogResponse;
/**
* Unauthorized
*/
401: HTTPExceptionResponse;
/**
* Forbidden
*/
403: HTTPExceptionResponse;
/**
* Not Found
*/
404: HTTPExceptionResponse;
/**
* Validation Error
*/
Expand Down
36 changes: 14 additions & 22 deletions tests/api_fastapi/core_api/routes/public/test_event_logs.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,10 @@ def setup(self, create_task_instance, session=None) -> dict[str, Log]:
owner_display_name=OWNER_DISPLAY_NAME,
task_instance=task_instance,
)
session.add(normal_log)
session.add(log_with_owner)
session.add(log_with_task_instance)
session.add(log_with_owner_and_task_instance)
session.add_all(
[normal_log, log_with_owner, log_with_task_instance, log_with_owner_and_task_instance]
)
session.commit()
session.refresh(normal_log)
session.refresh(log_with_owner)
session.refresh(log_with_task_instance)
session.refresh(log_with_owner_and_task_instance)
return {
EVENT_NORMAL: normal_log,
EVENT_WITH_OWNER: log_with_owner,
Expand Down Expand Up @@ -163,23 +158,20 @@ def test_get_event_log(self, test_client, setup, event_log_key, expected_status_
if expected_status_code != 200:
return

resp_json = response.json()
when = resp_json["when"]
logical_date = resp_json["logical_date"]
expected_json = {
"event_log_id": event_log_id,
"when": when,
"dag_id": None,
"task_id": None,
"run_id": None,
"when": event_log.dttm.isoformat().replace("+00:00", "Z") if event_log.dttm else None,
"dag_id": expected_body.get("dag_id"),
"task_id": expected_body.get("task_id"),
"run_id": expected_body.get("run_id"),
"map_index": event_log.map_index,
"try_number": event_log.try_number,
"event": None,
"logical_date": logical_date,
"owner": None,
"extra": None,
"event": expected_body.get("event"),
"logical_date": event_log.execution_date.isoformat().replace("+00:00", "Z")
if event_log.execution_date
else None,
"owner": expected_body.get("owner"),
"extra": expected_body.get("extra"),
}
for key, value in expected_body.items():
expected_json[key] = value

assert resp_json == expected_json
assert response.json() == expected_json

0 comments on commit 5faa9be

Please sign in to comment.