potiuk commented on code in PR #70530:
URL: https://github.com/apache/airflow/pull/70530#discussion_r3681991501
##########
providers/google/tests/unit/google/marketing_platform/operators/test_campaign_manager.py:
##########
@@ -87,6 +87,33 @@ def test_execute(self, mock_base_op, hook_mock):
profile_id=PROFILE_ID, report_id=REPORT_ID
)
+ @pytest.mark.parametrize(
+ ("report_name", "report_id", "match"),
+ [
+ pytest.param(None, None, "Please provide `report_name` or
`report_id`", id="both-missing"),
+ pytest.param(REPORT_NAME, REPORT_ID, "Please provide only one
parameter", id="both-provided"),
+ ],
+ )
+ @mock.patch(
+
"airflow.providers.google.marketing_platform.operators.campaign_manager.GoogleCampaignManagerHook"
+ )
+ def test_missing_or_conflicting_report_params_fail_at_execute_time(
+ self, hook_mock, report_name, report_id, match
+ ):
+ op = GoogleCampaignManagerDeleteReportOperator(
+ profile_id=PROFILE_ID,
+ report_name="{{ var.value.report_name }}",
+ api_version=API_VERSION,
+ task_id="test_task",
+ )
+ # Template rendering replaces the Jinja expressions with the resolved
values before execute.
+ op.report_name = report_name
+ op.report_id = report_id
+
+ with pytest.raises(ValueError, match=match):
+ op.execute(context=None)
Review Comment:
Two small things here.
`op.execute(context=None)` relies on nothing reading the context before the
raise — `mock.MagicMock()` or `{}` is sturdier if the check ever moves.
More substantively: the test simulates rendering by assigning
`op.report_name = report_name` directly, which tests the guard but not that
rendering actually feeds it. #70493 in the same batch does it properly with
`operator.render_template_fields({"var": {"value": {...}}})` followed by
`execute` — that exercises the real path and would catch a field being dropped
from `template_fields`. Worth borrowing that approach here, since "the value is
rendered before the check runs" is the actual contract this PR establishes.
---
Drafted-by: Claude Code (Opus 5); reviewed by @potiuk before posting
--
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]