pierrejeambrun commented on code in PR #54382:
URL: https://github.com/apache/airflow/pull/54382#discussion_r2426843198
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -146,6 +148,7 @@ def get_dags(
readable_dags_filter,
bundle_name,
bundle_version,
+ is_scheduled,
Review Comment:
Similarly can you also update the private `ui/dags` endpoint. `get_dags`
because the UI uses its own custom endpoint and the filter need to be there too.
##########
airflow-core/tests/unit/api_fastapi/common/test_parameters.py:
##########
@@ -38,3 +40,67 @@ def test_sort_param_max_number_of_filers(self):
),
):
param.to_orm(None)
+
+
+class TestIsDagScheduledFilter:
+ @pytest.fixture
+ def mock_dagmodel(self):
+ """
+ Patch DagModel in the parameters module's namespace so the filter uses
our mock.
+ """
+ with patch("airflow.api_fastapi.common.parameters.DagModel",
autospec=True) as mock_dm:
+ timetable_mock = MagicMock()
+ mock_dm.timetable_description = timetable_mock
+ yield mock_dm
+
+ @pytest.fixture
+ def mock_select(self):
+ """
+ Create a mock SQLAlchemy Select with .where().
+ """
+ select = MagicMock(spec=Select)
+ select.where.return_value = "filtered"
+ return select
+
+ def test_to_orm_value_none_returns_original(self, mock_select):
+ f = _IsDagScheduledFilter()
+ f.value = None
+ f.skip_none = True
+
+ result = f.to_orm(mock_select)
+
+ assert result == mock_select
+ mock_select.where.assert_not_called()
+
+ def test_to_orm_false_applies_never_filter(self, mock_select,
mock_dagmodel):
+ f = _IsDagScheduledFilter()
+ f.value = False
+ f.skip_none = True
+
+ mock_condition = MagicMock(name="ilike_condition")
+ mock_dagmodel.timetable_description.ilike.return_value = mock_condition
+
+ result = f.to_orm(mock_select)
+
+ assert result == "filtered"
+
mock_dagmodel.timetable_description.ilike.assert_called_once_with("Never%")
+ mock_select.where.assert_called_once_with(mock_condition)
+
+ def test_to_orm_true_applies_not_never_filter(self, mock_select,
mock_dagmodel):
+ f = _IsDagScheduledFilter()
+ f.value = True
+ f.skip_none = True
+
+ mock_condition = MagicMock(name="not_like_condition")
+ mock_dagmodel.timetable_description.not_like.return_value =
mock_condition
+
+ result = f.to_orm(mock_select)
+
+ assert result == "filtered"
+
mock_dagmodel.timetable_description.not_like.assert_called_once_with("Never%")
+ mock_select.where.assert_called_once_with(mock_condition)
+
+ def test_depends_sets_value(self):
+ f = _IsDagScheduledFilter.depends(True)
+ assert isinstance(f, _IsDagScheduledFilter)
+ assert f.value is True
Review Comment:
Instead of mocking everything, can you add remove those tests, and add one
in `public/test_dags.py` `test_get_dags`.
--
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]