innovark37 commented on code in PR #40885:
URL: https://github.com/apache/superset/pull/40885#discussion_r3601580802
##########
tests/unit_tests/commands/report/execute_test.py:
##########
@@ -1326,6 +1327,197 @@ def
test_get_csv_data_keeps_screenshot_fallback_without_query_context(
post_chart_data.assert_not_called()
+def test_get_url_for_xlsx_report(mocker: MockerFixture) -> None:
+ """XLSX reports should request post-processed chart data."""
+ report_schedule = create_report_schedule(mocker)
+ report_schedule.chart_id = 1
+ report_schedule.force_screenshot = False
+ report_state = BaseReportState(
+ report_schedule, "January 1, 2021", "execution_id_example"
+ )
+ get_url_path = mocker.patch(
+ "superset.commands.report.execute.get_url_path",
+ return_value="/api/v1/chart/1/data/xlsx",
+ )
+
+ url = report_state._get_url(result_format=ChartDataResultFormat.XLSX)
+
+ assert url == "/api/v1/chart/1/data/xlsx"
+ get_url_path.assert_called_once_with(
+ "ChartDataRestApi.get_data",
+ pk=1,
+ format=ChartDataResultFormat.XLSX.value,
+ type=ChartDataResultType.POST_PROCESSED.value,
+ force="false",
+ )
+
+
+def test_get_chart_data_rejects_non_table_format(mocker: MockerFixture) ->
None:
+ """Chart data retrieval should reject formats it cannot download."""
+ report_state = BaseReportState(
+ create_report_schedule(mocker),
+ "January 1, 2021",
+ "execution_id_example",
+ )
+ get_url = mocker.patch.object(report_state, "_get_url")
+
+ with pytest.raises(
+ ReportScheduleExecuteUnexpectedError,
+ match="Unsupported chart data result format: json",
+ ):
+ report_state._get_chart_data(ChartDataResultFormat.JSON)
+
+ get_url.assert_not_called()
+
+
+def _mock_xlsx_chart_data_dependencies(
+ mocker: MockerFixture,
+ report_state: BaseReportState,
+) -> tuple[MagicMock, dict[str, str]]:
+ """Mock external services used by the chart data download path."""
+ report_state._report_schedule.chart.query_context = None
+ mocker.patch.object(report_state, "_update_query_context")
+ mocker.patch("superset.commands.report.execute.db.session.refresh")
+ get_url = mocker.patch.object(
+ report_state,
+ "_get_url",
+ return_value="/api/v1/chart/1/data/xlsx",
+ )
+ mocker.patch(
+ "superset.commands.report.execute.get_executor",
+ return_value=(None, "report_executor"),
+ )
+ user = mocker.MagicMock(username="report_executor")
+ mocker.patch(
+ "superset.commands.report.execute.security_manager.find_user",
+ return_value=user,
+ )
+ auth_cookies = {"session": "cookie"}
+ auth_provider = mocker.patch(
+ "superset.commands.report.execute.machine_auth_provider_factory"
+ )
+ auth_provider.instance.get_auth_cookies.return_value = auth_cookies
+ return get_url, auth_cookies
+
+
+def test_get_xlsx_data_fetches_chart_data(
+ app: SupersetApp,
+ mocker: MockerFixture,
+) -> None:
+ """XLSX report data should be fetched through the chart data endpoint."""
+ report_state = BaseReportState(
+ create_report_schedule(mocker),
+ "January 1, 2021",
+ "execution_id_example",
+ )
+ get_url, auth_cookies = _mock_xlsx_chart_data_dependencies(mocker,
report_state)
+ get_chart_csv_data = mocker.patch(
+ "superset.commands.report.execute.get_chart_csv_data",
+ return_value=b"xlsx-data",
+ )
+
+ assert report_state._get_xlsx_data() == b"xlsx-data"
Review Comment:
Thanks, this was stale after the merge. `_get_xlsx_data` was removed in
favor of `_get_data(ChartDataResultFormat.XLSX)`, so I updated the XLSX tests
to use the current API.
--
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]