mirror of
https://github.com/apache/superset.git
synced 2026-05-12 19:35:17 +00:00
fix: error while parsing invalid json form_data (#12586)
* Fix error while parsing invalid json form_data * Refine error returned
This commit is contained in:
committed by
Daniel Gaspar
parent
233135e8ec
commit
d237cd63c0
@@ -1162,6 +1162,21 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
rv = self.post_assert_metric(CHART_DATA_URI, request_payload, "data")
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_chart_data_invalid_form_data(self):
|
||||
"""
|
||||
Chart data API: Test chart data with invalid form_data json
|
||||
"""
|
||||
self.login(username="admin")
|
||||
data = {"form_data": "NOT VALID JSON"}
|
||||
|
||||
rv = self.client.post(
|
||||
CHART_DATA_URI, data=data, content_type="multipart/form-data"
|
||||
)
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
self.assertEqual(rv.status_code, 400)
|
||||
self.assertEqual(response["message"], "Request is not JSON")
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_chart_data_query_result_type(self):
|
||||
"""
|
||||
@@ -1579,7 +1594,7 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"charts/imported_chart.yaml": "Chart already exists and `overwrite=true` was not passed",
|
||||
"charts/imported_chart.yaml": "Chart already exists and `overwrite=true` was not passed"
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -923,7 +923,7 @@ class TestUtils(SupersetTestCase):
|
||||
|
||||
self.assertEqual(
|
||||
form_data,
|
||||
{"time_range_endpoints": get_time_range_endpoints(form_data={}),},
|
||||
{"time_range_endpoints": get_time_range_endpoints(form_data={})},
|
||||
)
|
||||
|
||||
self.assertEqual(slc, None)
|
||||
@@ -992,6 +992,20 @@ class TestUtils(SupersetTestCase):
|
||||
|
||||
self.assertEqual(slc, None)
|
||||
|
||||
def test_get_form_data_corrupted_json(self) -> None:
|
||||
with app.test_request_context(
|
||||
data={"form_data": "{x: '2324'}"},
|
||||
query_string={"form_data": '{"baz": "bar"'},
|
||||
):
|
||||
form_data, slc = get_form_data()
|
||||
|
||||
self.assertEqual(
|
||||
form_data,
|
||||
{"time_range_endpoints": get_time_range_endpoints(form_data={})},
|
||||
)
|
||||
|
||||
self.assertEqual(slc, None)
|
||||
|
||||
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
|
||||
def test_log_this(self) -> None:
|
||||
# TODO: Add additional scenarios.
|
||||
|
||||
Reference in New Issue
Block a user