PNL0 commented on code in PR #51264:
URL: https://github.com/apache/airflow/pull/51264#discussion_r2155457642


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dags.py:
##########
@@ -392,6 +420,74 @@ 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
+

Review Comment:
   I just created the tests in my last commit.
   Let me know if everything is ok.



-- 
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]

Reply via email to