AmoghAtreya commented on code in PR #43176:
URL: https://github.com/apache/superset/pull/43176#discussion_r4178979079
##########
tests/unit_tests/mcp_service/chart/tool/test_get_chart_preview.py:
##########
@@ -556,6 +556,90 @@ def run(self) -> dict[str, Any]:
assert query["filters"] == [{"col": "gender", "op": "==", "val":
"boy"}]
assert "adhoc_filters" not in query
+ def test_table_preview_exposes_jinja_context(
+ self,
+ monkeypatch: pytest.MonkeyPatch,
+ ) -> None:
+ """Chart preview queries expose the same Jinja inputs as
get_chart_data."""
+ from flask import current_app
+
+ from superset.common.query_object import QueryObject
+ from tests.unit_tests.charts.data.form_data_test import (
+ assert_request_dependent_jinja_macros,
+ )
+
+ get_data_command_module = importlib.import_module(
+ "superset.commands.chart.data.get_data_command"
+ )
+ query = QueryObject(
+ filters=[{"col": "region", "op": "IN", "val": ["North"]}],
+ time_range="Last week",
+ columns=["region"],
+ metrics=["count"],
+ )
+ query_context = SimpleNamespace(
+ queries=[query],
+ form_data={"url_params": {"tenant": "acme"}},
+ )
+ observed: dict[str, bool] = {}
+
+ class ChartDataCommand:
+ def __init__(self, qc: object) -> None:
+ self.query_context = qc
+
+ def validate(self) -> None:
+ pass
+
+ def run(self) -> dict[str, Any]:
+ assert_request_dependent_jinja_macros()
+ observed["ran"] = True
+ return {
+ "queries": [
+ {
+ "data": [{"region": "North"}],
+ "colnames": ["region"],
+ "rowcount": 1,
+ }
+ ]
+ }
+
+ preview_module = importlib.import_module(
+ "superset.mcp_service.chart.tool.get_chart_preview"
+ )
+ monkeypatch.setattr(
+ preview_module,
+ "build_query_context_from_form_data",
Review Comment:
Replaced the untyped lambda with a typed nested
`_fake_build_query_context(*args: Any, **kwargs: Any) -> SimpleNamespace`.
Pre-existing lambdas left as-is.
--
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]