Lee-W commented on code in PR #46053: URL: https://github.com/apache/airflow/pull/46053#discussion_r1943912405
########## tests/www/test_utils.py: ########## @@ -663,6 +668,139 @@ def test_filter_lte_none_value_apply(self): assert result_query_filter == self.mock_query +class TestXComFilter: + def setup_method(self): + self.mock_datamodel = MagicMock() + self.mock_query = MagicMock(spec=Query) + self.mock_column_name = "test_column" + + def _assert_filter_query( + self, + xcom_filter, + raw_value: str, + expected_expr_builder: Callable[[ColumnElement, str], ColumnElement], + convert_value: bool = False, + ) -> None: + """ + A helper function to assert the filter query. + + :param xcom_filter: The XCom filter instance (e.g., XComFilterStartsWith). + :param raw_value: The raw string value we want to filter on. + :param expected_expr_builder: A function that takes in `returned_field` and returns the expected SQL expression. + :param convert_value: Whether to run `set_value_to_type(...)` on the raw_value. + """ + returned_query, returned_field = get_field_setup_query( + self.mock_query, self.mock_datamodel, self.mock_column_name + ) + + if convert_value: + value = set_value_to_type(self.mock_datamodel, self.mock_column_name, raw_value) + else: + value = raw_value + xcom_filter.apply(self.mock_query, value) + self.mock_query.filter.assert_called_once() + actual_filter_arg = self.mock_query.filter.call_args[0][0] + expected_filter_arg = expected_expr_builder(returned_field, value) + assert str(actual_filter_arg) == str(expected_filter_arg) + + def test_xcom_filter_start_with_apply(self): Review Comment: We could further refactor it through `@pytest.mark.parameterize` if you want, but I'm good with the current implementation. Nice work! -- 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: commits-unsubscr...@airflow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org