You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by el...@apache.org on 2023/10/19 23:41:35 UTC

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

This is an automated email from the ASF dual-hosted git repository.

elizabeth pushed a commit to branch 2.1
in repository https://gitbox.apache.org/repos/asf/superset.git

commit d80f326d531f04bc871e55bf3ca2a33d7faff808
Author: Zef Lin <ze...@preset.io>
AuthorDate: Fri Jul 21 16:31:41 2023 -0700

    chore(view_api): return application/json as content-type for api/v1/form_data endpoint (#24758)
    
    (cherry picked from commit 0631a8086cd95f3b6e88b31d29c7fbc2e1d20b25)
---
 superset/views/api.py                       |  2 +-
 tests/integration_tests/charts/api_tests.py | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/superset/views/api.py b/superset/views/api.py
index fc7c5b76d2..820048d7c4 100644
--- a/superset/views/api.py
+++ b/superset/views/api.py
@@ -87,7 +87,7 @@ class Api(BaseSupersetView):
 
         update_time_range(form_data)
 
-        return json.dumps(form_data)
+        return self.json_response(form_data)
 
     @api
     @handle_api_exception
diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py
index 02c5ce261e..98c4a49683 100644
--- a/tests/integration_tests/charts/api_tests.py
+++ b/tests/integration_tests/charts/api_tests.py
@@ -1371,6 +1371,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",