Vitor-Avila commented on code in PR #31840:
URL: https://github.com/apache/superset/pull/31840#discussion_r1915875141
##########
tests/integration_tests/reports/alert_tests.py:
##########
@@ -98,6 +99,86 @@ def test_execute_query_as_report_executor(
app.config["ALERT_REPORTS_EXECUTE_AS"] = original_config
+def test_execute_query_mutate_query_enabled(
+ mocker: MockerFixture,
+ app_context: AppContext,
+ get_user,
+) -> None:
+ from superset.commands.report.alert import AlertCommand
+ from superset.reports.models import ReportSchedule
+
+ def mock_mutate_query(sql: str, **kwargs: Any) -> str:
+ return "before " + sql + " after"
+
+ app.config["SQL_QUERY_MUTATOR"] = mock_mutate_query
+ app.config["MUTATE_ALERT_QUERY"] = True
+ app.config["ALERT_REPORTS_EXECUTE_AS"] = [ExecutorType.OWNER]
+
+ mocker.patch("superset.commands.report.alert.override_user")
+ mock_df = mocker.MagicMock(spec=pd.DataFrame)
+ mock_df.empty = True
+ mock_database = get_example_database()
+ mock_get_df = mocker.patch.object(mock_database, "get_df",
return_value=mock_df)
+ mock_limited_sql = mocker.patch.object(
+ mock_database, "apply_limit_to_sql", return_value="SELECT 1\nLIMIT 2"
+ )
+
+ report_schedule = ReportSchedule(
+ created_by=get_user("admin"),
+ owners=[get_user("admin")],
+ type=ReportScheduleType.ALERT,
+ description="description",
+ crontab="0 9 * * *",
+ creation_method=ReportCreationMethod.ALERTS_REPORTS,
+ sql="SELECT 1",
+ grace_period=14400,
+ working_timeout=3600,
+ database=mock_database,
+ validator_config_json='{"op": "==", "threshold": 1}',
+ )
+
+ AlertCommand(report_schedule=report_schedule,
execution_id=uuid.uuid4()).run()
+ mock_get_df.assert_called_once_with(
+ sql=f"before {mock_limited_sql.return_value} after"
+ )
+
+
+def test_execute_query_mutate_query_disabled(
+ mocker: MockerFixture,
+ app_context: AppContext,
+ get_user,
+) -> None:
+ from superset.commands.report.alert import AlertCommand
+ from superset.reports.models import ReportSchedule
+
+ def mock_mutate_query(sql: str, **kwargs: Any) -> str:
+ return "before " + sql + " after"
+
+ app.config["SQL_QUERY_MUTATOR"] = mock_mutate_query
+ app.config["MUTATE_ALERT_QUERY"] = False
+ app.config["ALERT_REPORTS_EXECUTE_AS"] = [ExecutorType.OWNER]
Review Comment:
good catch! Changed the test logic a bit and re-applied the initial app
configs at the end of them 🙌
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]