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:
Duy Nguyen Hoang
2021-01-19 23:15:16 +07:00
committed by Daniel Gaspar
parent 233135e8ec
commit d237cd63c0
4 changed files with 49 additions and 8 deletions

View File

@@ -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"
}
}