fat-catTW commented on code in PR #72715:
URL: https://github.com/apache/airflow/pull/72715#discussion_r4371778957


##########
airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_bundles.py:
##########
@@ -944,3 +949,112 @@ def 
test_404_for_a_bundle_whose_dags_are_not_readable(self, dag_scoped_client):
 
     def test_404_for_an_unknown_bundle(self, dag_scoped_client):
         assert 
dag_scoped_client.get("/dagBundles/no_such_bundle/files").status_code == 404
+
+
+class TestRefreshDagBundle:
+    def setup_method(self):
+        clear_db_dag_parsing_requests()
+        clear_db_dags()
+        clear_db_dag_bundles()
+        clear_db_logs()
+
+    def teardown_method(self):
+        clear_db_dag_parsing_requests()
+        clear_db_dags()
+        clear_db_dag_bundles()
+        clear_db_logs()
+
+    @pytest.fixture
+    def auth_manager(self, test_client):
+        auth_manager = get_auth_manager()
+        with mock.patch.object(auth_manager, "is_authorized_dag"):
+            yield auth_manager
+
+    def test_global_bundle_refresh_uses_dag_permission(self, auth_manager, 
session, test_client):
+        session.add(DagBundleModel(name="global-bundle"))
+        session.commit()
+        auth_manager.is_authorized_dag.return_value = True
+
+        response = test_client.post("/dagBundles/global-bundle/refresh")
+
+        assert response.status_code == 202
+        assert response.json() == {"bundle_name": "global-bundle"}
+        auth_manager.is_authorized_dag.assert_called_with(
+            method="PUT",
+            details=DagDetails(id=None, team_name=None),
+            user=mock.ANY,
+        )
+        parsing_requests = 
session.scalars(select(DagPriorityParsingRequest)).all()
+        assert len(parsing_requests) == 1
+        assert parsing_requests[0].bundle_name == "global-bundle"
+        assert parsing_requests[0].relative_fileloc is None
+        _check_last_log(session, dag_id=None, event="refresh_dag_bundle", 
logical_date=None)
+
+    def test_repeated_refresh_uses_existing_pending_request(self, 
auth_manager, session, test_client):
+        session.add(DagBundleModel(name="global-bundle"))
+        session.commit()
+        auth_manager.is_authorized_dag.return_value = True
+
+        first_response = test_client.post("/dagBundles/global-bundle/refresh")
+        second_response = test_client.post("/dagBundles/global-bundle/refresh")
+
+        assert first_response.status_code == second_response.status_code == 202

Review Comment:
   updated!



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