Skip to content

Commit

Permalink
chore(view_api): return application/json as content-type for api/v1/f…
Browse files Browse the repository at this point in the history
…orm_data endpoint (apache#24758)
  • Loading branch information
Zef Lin committed Jul 21, 2023
1 parent e060042 commit 0631a80
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion superset/views/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def query_form_data(self) -> FlaskResponse: # pylint: disable=no-self-use

update_time_range(form_data)

return json.dumps(form_data)
return self.json_response(form_data)

@api
@handle_api_exception
Expand Down
14 changes: 14 additions & 0 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1424,6 +1424,20 @@ def test_get_time_range(self):
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",
Expand Down

0 comments on commit 0631a80

Please sign in to comment.