Lee-W commented on code in PR #46053:
URL: https://github.com/apache/airflow/pull/46053#discussion_r1944081041
##########
tests/www/test_utils.py:
##########
@@ -663,6 +668,115 @@ 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)
+
+ @pytest.mark.parametrize(
+ "filter_class, raw_value, convert_value, expected_expr_builder",
+ [
+ (
+ utils.XComFilterStartsWith,
+ "test_value",
+ False,
+ lambda field, v: func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"{v}%"),
+ ),
+ (
+ utils.XComFilterEndsWith,
+ "test_value",
+ False,
+ lambda field, v: func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"%{v}"),
+ ),
+ (
+ utils.XComFilterEqual,
+ "test_value",
+ True,
+ lambda field, v: func.btrim(func.convert_from(field, "UTF8"),
'"') == v,
+ ),
+ (
+ utils.XComFilterContains,
+ "test_value",
+ False,
+ lambda field, v: func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"%{v}%"),
+ ),
+ (
+ utils.XComFilterNotStartsWith,
+ "test_value",
+ False,
+ lambda field, v: ~func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"{v}%"),
+ ),
+ (
+ utils.XComFilterNotEndsWith,
+ "test_value",
+ False,
+ lambda field, v: ~func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"%{v}"),
+ ),
+ (
+ utils.XComFilterNotContains,
+ "test_value",
+ False,
+ lambda field, v: ~func.btrim(func.convert_from(field, "UTF8"),
'"').ilike(f"%{v}%"),
+ ),
+ (
+ utils.XComFilterNotEqual,
+ "test_value",
Review Comment:
"test_value" probably doesn't need to be parameterized. This is identical
--
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]