pierrejeambrun commented on code in PR #43406: URL: https://github.com/apache/airflow/pull/43406#discussion_r1819085350
########## tests/api_fastapi/core_api/routes/public/test_event_logs.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime, timezone + +import pytest + +from airflow.models.log import Log +from airflow.utils.session import provide_session + +from tests_common.test_utils.db import clear_db_logs, clear_db_runs + +pytestmark = pytest.mark.db_test + +DAG_ID = "TEST_DAG_ID" +DAG_RUN_ID = "TEST_DAG_RUN_ID" +TASK_ID = "TEST_TASK_ID" +DAG_EXECUTION_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc) +OWNER = "TEST_OWNER" +OWNER_DISPLAY_NAME = "Test Owner" +OWNER_AIRFLOW = "airflow" +TASK_INSTANCE_EVENT = "TASK_INSTANCE_EVENT" +TASK_INSTANCE_OWNER = "TASK_INSTANCE_OWNER" +TASK_INSTANCE_OWNER_DISPLAY_NAME = "Task Instance Owner" + + +EVENT_NORMAL = "NORMAL_EVENT" +EVENT_WITH_OWNER = "EVENT_WITH_OWNER" +EVENT_WITH_TASK_INSTANCE = "EVENT_WITH_TASK_INSTANCE" +EVENT_WITH_OWNER_AND_TASK_INSTANCE = "EVENT_WITH_OWNER_AND_TASK_INSTANCE" +EVENT_NON_EXISTED_ID = 9999 + + +class TestEventLogsEndpoint: + """Common class for /public/eventLogs related unit tests.""" + + @staticmethod + def _clear_db(): + clear_db_logs() + clear_db_runs() + + @pytest.fixture(autouse=True) + @provide_session + def setup(self, create_task_instance, session=None) -> dict[str, Log]: + """ + Setup event logs for testing. + :return: Dictionary with event log keys and their corresponding IDs. + """ + self._clear_db() + # create task instances for testing + task_instance = create_task_instance( + session=session, + dag_id=DAG_ID, + task_id=TASK_ID, + run_id=DAG_RUN_ID, + execution_date=DAG_EXECUTION_DATE, + ) + normal_log = Log( + event=EVENT_NORMAL, + ) + log_with_owner = Log( + event=EVENT_WITH_OWNER, + owner=OWNER, + owner_display_name=OWNER_DISPLAY_NAME, + ) + log_with_task_instance = Log( + event=TASK_INSTANCE_EVENT, + task_instance=task_instance, + ) + log_with_owner_and_task_instance = Log( + event=EVENT_WITH_OWNER_AND_TASK_INSTANCE, + owner=OWNER, + 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.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, + TASK_INSTANCE_EVENT: log_with_task_instance, + EVENT_WITH_OWNER_AND_TASK_INSTANCE: log_with_owner_and_task_instance, + } + + def teardown_method(self) -> None: + self._clear_db() + + +class TestGetEventLog(TestEventLogsEndpoint): + @pytest.mark.parametrize( + "event_log_key, expected_status_code, expected_body", + [ + ( + EVENT_NORMAL, + 200, + { + "event": EVENT_NORMAL, + }, + ), + ( + EVENT_WITH_OWNER, + 200, + { + "event": EVENT_WITH_OWNER, + "owner": OWNER, + }, + ), + ( + TASK_INSTANCE_EVENT, + 200, + { + "dag_id": DAG_ID, + "event": TASK_INSTANCE_EVENT, + "map_index": -1, + "owner": OWNER_AIRFLOW, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + }, + ), + ( + EVENT_WITH_OWNER_AND_TASK_INSTANCE, + 200, + { + "dag_id": DAG_ID, + "event": EVENT_WITH_OWNER_AND_TASK_INSTANCE, + "map_index": -1, + "owner": OWNER, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + "try_number": 0, + }, + ), + ("not_existed_event_log_key", 404, {}), + ], + ) + def test_get_event_log(self, test_client, setup, event_log_key, expected_status_code, expected_body): + event_log: Log | None = setup.get(event_log_key, None) + event_log_id = event_log.id if event_log else EVENT_NON_EXISTED_ID + response = test_client.get(f"/public/eventLogs/{event_log_id}") + assert response.status_code == expected_status_code + 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, Review Comment: This logic is wrong. You construct the `expected_json` based on the test `reponse` that we actually want to assert. ("when", "logical_date" etc...). ########## airflow/api_fastapi/core_api/routes/public/event_logs.py: ########## @@ -0,0 +1,47 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from fastapi import Depends, HTTPException +from sqlalchemy import select +from sqlalchemy.orm import Session +from typing_extensions import Annotated + +from airflow.api_fastapi.common.db.common import ( + get_session, +) +from airflow.api_fastapi.common.router import AirflowRouter +from airflow.api_fastapi.core_api.serializers.event_logs import ( + EventLogResponse, +) +from airflow.models import Log + +event_logs_router = AirflowRouter(tags=["Event Log"], prefix="/eventLogs") + + +@event_logs_router.get("/{event_log_id}") Review Comment: we are missing the errors documentation. (422 is already handled automatically by pydantic, 404 need to be manually added) ########## tests/api_fastapi/core_api/routes/public/test_event_logs.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime, timezone + +import pytest + +from airflow.models.log import Log +from airflow.utils.session import provide_session + +from tests_common.test_utils.db import clear_db_logs, clear_db_runs + +pytestmark = pytest.mark.db_test + +DAG_ID = "TEST_DAG_ID" +DAG_RUN_ID = "TEST_DAG_RUN_ID" +TASK_ID = "TEST_TASK_ID" +DAG_EXECUTION_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc) +OWNER = "TEST_OWNER" +OWNER_DISPLAY_NAME = "Test Owner" +OWNER_AIRFLOW = "airflow" +TASK_INSTANCE_EVENT = "TASK_INSTANCE_EVENT" +TASK_INSTANCE_OWNER = "TASK_INSTANCE_OWNER" +TASK_INSTANCE_OWNER_DISPLAY_NAME = "Task Instance Owner" + + +EVENT_NORMAL = "NORMAL_EVENT" +EVENT_WITH_OWNER = "EVENT_WITH_OWNER" +EVENT_WITH_TASK_INSTANCE = "EVENT_WITH_TASK_INSTANCE" +EVENT_WITH_OWNER_AND_TASK_INSTANCE = "EVENT_WITH_OWNER_AND_TASK_INSTANCE" +EVENT_NON_EXISTED_ID = 9999 + + +class TestEventLogsEndpoint: + """Common class for /public/eventLogs related unit tests.""" + + @staticmethod + def _clear_db(): + clear_db_logs() + clear_db_runs() + + @pytest.fixture(autouse=True) + @provide_session + def setup(self, create_task_instance, session=None) -> dict[str, Log]: + """ + Setup event logs for testing. + :return: Dictionary with event log keys and their corresponding IDs. + """ + self._clear_db() + # create task instances for testing + task_instance = create_task_instance( + session=session, + dag_id=DAG_ID, + task_id=TASK_ID, + run_id=DAG_RUN_ID, + execution_date=DAG_EXECUTION_DATE, + ) + normal_log = Log( + event=EVENT_NORMAL, + ) + log_with_owner = Log( + event=EVENT_WITH_OWNER, + owner=OWNER, + owner_display_name=OWNER_DISPLAY_NAME, + ) + log_with_task_instance = Log( + event=TASK_INSTANCE_EVENT, + task_instance=task_instance, + ) + log_with_owner_and_task_instance = Log( + event=EVENT_WITH_OWNER_AND_TASK_INSTANCE, + owner=OWNER, + 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) Review Comment: add_all ########## tests/api_fastapi/core_api/routes/public/test_event_logs.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime, timezone + +import pytest + +from airflow.models.log import Log +from airflow.utils.session import provide_session + +from tests_common.test_utils.db import clear_db_logs, clear_db_runs + +pytestmark = pytest.mark.db_test + +DAG_ID = "TEST_DAG_ID" +DAG_RUN_ID = "TEST_DAG_RUN_ID" +TASK_ID = "TEST_TASK_ID" +DAG_EXECUTION_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc) +OWNER = "TEST_OWNER" +OWNER_DISPLAY_NAME = "Test Owner" +OWNER_AIRFLOW = "airflow" +TASK_INSTANCE_EVENT = "TASK_INSTANCE_EVENT" +TASK_INSTANCE_OWNER = "TASK_INSTANCE_OWNER" +TASK_INSTANCE_OWNER_DISPLAY_NAME = "Task Instance Owner" + + +EVENT_NORMAL = "NORMAL_EVENT" +EVENT_WITH_OWNER = "EVENT_WITH_OWNER" +EVENT_WITH_TASK_INSTANCE = "EVENT_WITH_TASK_INSTANCE" +EVENT_WITH_OWNER_AND_TASK_INSTANCE = "EVENT_WITH_OWNER_AND_TASK_INSTANCE" +EVENT_NON_EXISTED_ID = 9999 + + +class TestEventLogsEndpoint: + """Common class for /public/eventLogs related unit tests.""" + + @staticmethod + def _clear_db(): + clear_db_logs() + clear_db_runs() + + @pytest.fixture(autouse=True) + @provide_session + def setup(self, create_task_instance, session=None) -> dict[str, Log]: + """ + Setup event logs for testing. + :return: Dictionary with event log keys and their corresponding IDs. + """ + self._clear_db() + # create task instances for testing + task_instance = create_task_instance( + session=session, + dag_id=DAG_ID, + task_id=TASK_ID, + run_id=DAG_RUN_ID, + execution_date=DAG_EXECUTION_DATE, + ) + normal_log = Log( + event=EVENT_NORMAL, + ) + log_with_owner = Log( + event=EVENT_WITH_OWNER, + owner=OWNER, + owner_display_name=OWNER_DISPLAY_NAME, + ) + log_with_task_instance = Log( + event=TASK_INSTANCE_EVENT, + task_instance=task_instance, + ) + log_with_owner_and_task_instance = Log( + event=EVENT_WITH_OWNER_AND_TASK_INSTANCE, + owner=OWNER, + 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.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, + TASK_INSTANCE_EVENT: log_with_task_instance, + EVENT_WITH_OWNER_AND_TASK_INSTANCE: log_with_owner_and_task_instance, + } + + def teardown_method(self) -> None: + self._clear_db() + + +class TestGetEventLog(TestEventLogsEndpoint): + @pytest.mark.parametrize( + "event_log_key, expected_status_code, expected_body", + [ + ( + EVENT_NORMAL, + 200, + { + "event": EVENT_NORMAL, + }, + ), + ( + EVENT_WITH_OWNER, + 200, + { + "event": EVENT_WITH_OWNER, + "owner": OWNER, + }, + ), + ( + TASK_INSTANCE_EVENT, + 200, + { + "dag_id": DAG_ID, + "event": TASK_INSTANCE_EVENT, + "map_index": -1, + "owner": OWNER_AIRFLOW, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + }, + ), + ( + EVENT_WITH_OWNER_AND_TASK_INSTANCE, + 200, + { + "dag_id": DAG_ID, + "event": EVENT_WITH_OWNER_AND_TASK_INSTANCE, + "map_index": -1, + "owner": OWNER, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + "try_number": 0, + }, + ), + ("not_existed_event_log_key", 404, {}), + ], + ) + def test_get_event_log(self, test_client, setup, event_log_key, expected_status_code, expected_body): + event_log: Log | None = setup.get(event_log_key, None) + event_log_id = event_log.id if event_log else EVENT_NON_EXISTED_ID + response = test_client.get(f"/public/eventLogs/{event_log_id}") + assert response.status_code == expected_status_code + 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, Review Comment: I don't think `task_id` or `dag_id` should be None for task_instance event. ########## tests/api_fastapi/core_api/routes/public/test_event_logs.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime, timezone + +import pytest + +from airflow.models.log import Log +from airflow.utils.session import provide_session + +from tests_common.test_utils.db import clear_db_logs, clear_db_runs + +pytestmark = pytest.mark.db_test + +DAG_ID = "TEST_DAG_ID" +DAG_RUN_ID = "TEST_DAG_RUN_ID" +TASK_ID = "TEST_TASK_ID" +DAG_EXECUTION_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc) +OWNER = "TEST_OWNER" +OWNER_DISPLAY_NAME = "Test Owner" +OWNER_AIRFLOW = "airflow" +TASK_INSTANCE_EVENT = "TASK_INSTANCE_EVENT" +TASK_INSTANCE_OWNER = "TASK_INSTANCE_OWNER" +TASK_INSTANCE_OWNER_DISPLAY_NAME = "Task Instance Owner" + + +EVENT_NORMAL = "NORMAL_EVENT" +EVENT_WITH_OWNER = "EVENT_WITH_OWNER" +EVENT_WITH_TASK_INSTANCE = "EVENT_WITH_TASK_INSTANCE" +EVENT_WITH_OWNER_AND_TASK_INSTANCE = "EVENT_WITH_OWNER_AND_TASK_INSTANCE" +EVENT_NON_EXISTED_ID = 9999 + + +class TestEventLogsEndpoint: + """Common class for /public/eventLogs related unit tests.""" + + @staticmethod + def _clear_db(): + clear_db_logs() + clear_db_runs() + + @pytest.fixture(autouse=True) + @provide_session + def setup(self, create_task_instance, session=None) -> dict[str, Log]: + """ + Setup event logs for testing. + :return: Dictionary with event log keys and their corresponding IDs. + """ + self._clear_db() + # create task instances for testing + task_instance = create_task_instance( + session=session, + dag_id=DAG_ID, + task_id=TASK_ID, + run_id=DAG_RUN_ID, + execution_date=DAG_EXECUTION_DATE, + ) + normal_log = Log( + event=EVENT_NORMAL, + ) + log_with_owner = Log( + event=EVENT_WITH_OWNER, + owner=OWNER, + owner_display_name=OWNER_DISPLAY_NAME, + ) + log_with_task_instance = Log( + event=TASK_INSTANCE_EVENT, + task_instance=task_instance, + ) + log_with_owner_and_task_instance = Log( + event=EVENT_WITH_OWNER_AND_TASK_INSTANCE, + owner=OWNER, + 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.commit() + session.refresh(normal_log) + session.refresh(log_with_owner) + session.refresh(log_with_task_instance) + session.refresh(log_with_owner_and_task_instance) Review Comment: commit should automatically refresh objects. ########## tests/api_fastapi/core_api/routes/public/test_event_logs.py: ########## @@ -0,0 +1,185 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime, timezone + +import pytest + +from airflow.models.log import Log +from airflow.utils.session import provide_session + +from tests_common.test_utils.db import clear_db_logs, clear_db_runs + +pytestmark = pytest.mark.db_test + +DAG_ID = "TEST_DAG_ID" +DAG_RUN_ID = "TEST_DAG_RUN_ID" +TASK_ID = "TEST_TASK_ID" +DAG_EXECUTION_DATE = datetime(2024, 6, 15, 0, 0, tzinfo=timezone.utc) +OWNER = "TEST_OWNER" +OWNER_DISPLAY_NAME = "Test Owner" +OWNER_AIRFLOW = "airflow" +TASK_INSTANCE_EVENT = "TASK_INSTANCE_EVENT" +TASK_INSTANCE_OWNER = "TASK_INSTANCE_OWNER" +TASK_INSTANCE_OWNER_DISPLAY_NAME = "Task Instance Owner" + + +EVENT_NORMAL = "NORMAL_EVENT" +EVENT_WITH_OWNER = "EVENT_WITH_OWNER" +EVENT_WITH_TASK_INSTANCE = "EVENT_WITH_TASK_INSTANCE" +EVENT_WITH_OWNER_AND_TASK_INSTANCE = "EVENT_WITH_OWNER_AND_TASK_INSTANCE" +EVENT_NON_EXISTED_ID = 9999 + + +class TestEventLogsEndpoint: + """Common class for /public/eventLogs related unit tests.""" + + @staticmethod + def _clear_db(): + clear_db_logs() + clear_db_runs() + + @pytest.fixture(autouse=True) + @provide_session + def setup(self, create_task_instance, session=None) -> dict[str, Log]: + """ + Setup event logs for testing. + :return: Dictionary with event log keys and their corresponding IDs. + """ + self._clear_db() + # create task instances for testing + task_instance = create_task_instance( + session=session, + dag_id=DAG_ID, + task_id=TASK_ID, + run_id=DAG_RUN_ID, + execution_date=DAG_EXECUTION_DATE, + ) + normal_log = Log( + event=EVENT_NORMAL, + ) + log_with_owner = Log( + event=EVENT_WITH_OWNER, + owner=OWNER, + owner_display_name=OWNER_DISPLAY_NAME, + ) + log_with_task_instance = Log( + event=TASK_INSTANCE_EVENT, + task_instance=task_instance, + ) + log_with_owner_and_task_instance = Log( + event=EVENT_WITH_OWNER_AND_TASK_INSTANCE, + owner=OWNER, + 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.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, + TASK_INSTANCE_EVENT: log_with_task_instance, + EVENT_WITH_OWNER_AND_TASK_INSTANCE: log_with_owner_and_task_instance, + } + + def teardown_method(self) -> None: + self._clear_db() + + +class TestGetEventLog(TestEventLogsEndpoint): + @pytest.mark.parametrize( + "event_log_key, expected_status_code, expected_body", + [ + ( + EVENT_NORMAL, + 200, + { + "event": EVENT_NORMAL, + }, + ), + ( + EVENT_WITH_OWNER, + 200, + { + "event": EVENT_WITH_OWNER, + "owner": OWNER, + }, + ), + ( + TASK_INSTANCE_EVENT, + 200, + { + "dag_id": DAG_ID, + "event": TASK_INSTANCE_EVENT, + "map_index": -1, + "owner": OWNER_AIRFLOW, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + }, + ), + ( + EVENT_WITH_OWNER_AND_TASK_INSTANCE, + 200, + { + "dag_id": DAG_ID, + "event": EVENT_WITH_OWNER_AND_TASK_INSTANCE, + "map_index": -1, + "owner": OWNER, + "run_id": DAG_RUN_ID, + "task_id": TASK_ID, + "try_number": 0, + }, + ), + ("not_existed_event_log_key", 404, {}), + ], + ) + def test_get_event_log(self, test_client, setup, event_log_key, expected_status_code, expected_body): + event_log: Log | None = setup.get(event_log_key, None) + event_log_id = event_log.id if event_log else EVENT_NON_EXISTED_ID + response = test_client.get(f"/public/eventLogs/{event_log_id}") + assert response.status_code == expected_status_code + 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, + "map_index": event_log.map_index, + "try_number": event_log.try_number, + "event": None, + "logical_date": logical_date, + "owner": None, + "extra": None, + } + for key, value in expected_body.items(): + expected_json[key] = value Review Comment: You can just assert equal two dicts, no need to iterate like this. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
