PNL0 commented on code in PR #51264: URL: https://github.com/apache/airflow/pull/51264#discussion_r2160444610
########## airflow-core/src/airflow/ui/src/pages/Dashboard/FavoriteDags/FavoriteDags.tsx: ########## @@ -0,0 +1,96 @@ +/*! + * 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. + */ +import { Box, Flex, Heading, SimpleGrid, Text } from "@chakra-ui/react"; +import { useQueryClient } from "@tanstack/react-query"; +import { useEffect, useMemo, useState } from "react"; +import { useTranslation } from "react-i18next"; +import { FiStar } from "react-icons/fi"; +import { useLocation } from "react-router-dom"; + +import { useDagServiceGetDags } from "openapi/queries"; + +import { FavoriteDagCard } from "./FavoriteDagCard"; + +const MAX_VISIBLE = 5; Review Comment: Done. ########## airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py: ########## @@ -392,6 +420,90 @@ def test_patch_dags_should_response_403(self, unauthorized_test_client): assert response.status_code == 403 +class TestFavoriteDag(TestDagEndpoint): + """Unit tests for favoriting a DAG.""" + + @pytest.mark.parametrize( + "dag_id, expected_status_code, expected_exist_in_favorites", + [ + ("fake_dag_id", 404, None), + (DAG1_ID, 200, True), + ], + ) + def test_favorite_dag( + self, test_client, dag_id, expected_status_code, expected_exist_in_favorites, session + ): + response = test_client.post(f"/dags/{dag_id}/favorite") + assert response.status_code == expected_status_code + + if expected_status_code == 200: + result = session.execute( + select(DagFavorite).where(DagFavorite.dag_id == dag_id, DagFavorite.user_id == "test") + ).first() + assert result is not None if expected_exist_in_favorites else result is None + check_last_log(session, dag_id=dag_id, event="favorite_dag", logical_date=None) + + def test_favorite_dag_should_response_401(self, unauthenticated_test_client): + response = unauthenticated_test_client.post(f"/dags/{DAG1_ID}/favorite") + assert response.status_code == 401 + + def test_favorite_dag_should_response_403(self, unauthorized_test_client): + response = unauthorized_test_client.post(f"/dags/{DAG1_ID}/favorite") + assert response.status_code == 403 + + def test_favoriting_already_favorited_dag_returns_409(self, test_client): + response = test_client.post(f"/dags/{DAG1_ID}/favorite") + assert response.status_code == 200 + + response = test_client.post(f"/dags/{DAG1_ID}/favorite") + assert response.status_code == 409 + + +class TestUnfavoriteDag(TestDagEndpoint): + """Unit tests for unfavoriting a DAG.""" + + @pytest.mark.parametrize( + "dag_id, expected_status_code, expected_exist_in_favorites", + [ + ("fake_dag_id", 404, None), + (DAG1_ID, 200, False), + ], + ) + def test_unfavorite_dag( + self, test_client, dag_id, expected_status_code, expected_exist_in_favorites, session + ): + if dag_id != "fake_dag_id": + session.execute(insert(DagFavorite).values(dag_id=dag_id, user_id="test")) + session.commit() + + response = test_client.post(f"/dags/{dag_id}/unfavorite") + assert response.status_code == expected_status_code + + if expected_status_code == 200: + result = session.execute( + select(DagFavorite).where(DagFavorite.dag_id == dag_id, DagFavorite.user_id == "test") + ).first() + assert result is not None if expected_exist_in_favorites else result is None + check_last_log(session, dag_id=dag_id, event="unfavorite_dag", logical_date=None) + + def test_unfavorite_dag_should_response_401(self, unauthenticated_test_client): + response = unauthenticated_test_client.post(f"/dags/{DAG1_ID}/unfavorite") + assert response.status_code == 401 + + def test_unfavorite_dag_should_response_403(self, unauthorized_test_client): + response = unauthorized_test_client.post(f"/dags/{DAG1_ID}/unfavorite") + assert response.status_code == 403 + + def test_unfavoriting_dag_that_is_not_favorite_returns_409(self, test_client, session): + session.execute( + delete(DagFavorite).where(DagFavorite.dag_id == DAG1_ID, DagFavorite.user_id == "test") + ) + session.commit() Review Comment: Done. -- 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]
