Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice!


@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