fix: Ensure the reporting framework handles charts with no data (#23585)

This commit is contained in:
John Bodley
2023-04-06 07:30:27 +12:00
committed by GitHub
parent cd498c18ba
commit e8cfb31bff
3 changed files with 17 additions and 8 deletions

View File

@@ -18,9 +18,9 @@
import json
import pandas as pd
import pytest
from flask_babel import lazy_gettext as _
from numpy import True_
from pytest import raises
from sqlalchemy.orm.session import Session
from superset.charts.post_processing import apply_post_process, pivot_df, table
@@ -1389,7 +1389,7 @@ def test_apply_post_process_without_result_format():
result = {"queries": [{"result_format": "foo"}]}
form_data = {"viz_type": "pivot_table"}
with raises(Exception) as ex:
with pytest.raises(Exception) as ex:
apply_post_process(result, form_data)
assert ex.match("Result format foo not supported") == True
@@ -1659,12 +1659,13 @@ def test_apply_post_process_csv_format_empty_string():
}
def test_apply_post_process_csv_format_no_data():
@pytest.mark.parametrize("data", [None, "", "\n"])
def test_apply_post_process_csv_format_no_data(data):
"""
It should be able to process csv results with no data
"""
result = {"queries": [{"result_format": ChartDataResultFormat.CSV, "data": None}]}
result = {"queries": [{"result_format": ChartDataResultFormat.CSV, "data": data}]}
form_data = {
"datasource": "19__table",
"viz_type": "pivot_table_v2",
@@ -1726,7 +1727,7 @@ def test_apply_post_process_csv_format_no_data():
}
assert apply_post_process(result, form_data) == {
"queries": [{"result_format": ChartDataResultFormat.CSV, "data": None}]
"queries": [{"result_format": ChartDataResultFormat.CSV, "data": data}]
}