chore(view_api): return application/json as content-type for api/v1/form_data endpoint (#24758)

This commit is contained in:
Zef Lin 2023-07-21 16:31:41 -07:00 committed by GitHub
parent e06004292a
commit 0631a8086c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -86,7 +86,7 @@ class Api(BaseSupersetView):
update_time_range(form_data)
return json.dumps(form_data)
return self.json_response(form_data)
@api
@handle_api_exception

View File

@ -1424,6 +1424,20 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin):
self.assertEqual(rv.status_code, 200)
self.assertEqual(len(data["result"]), 3)
def test_query_form_data(self):
"""
Chart API: Test query form data
"""
self.login(username="admin")
slice = db.session.query(Slice).first()
uri = f"api/v1/form_data/?slice_id={slice.id if slice else None}"
rv = self.client.get(uri)
data = json.loads(rv.data.decode("utf-8"))
self.assertEqual(rv.status_code, 200)
self.assertEqual(rv.content_type, "application/json")
if slice:
self.assertEqual(data["slice_id"], slice.id)
@pytest.mark.usefixtures(
"load_unicode_dashboard_with_slice",
"load_energy_table_with_slice",