From 316e0874e1352808c94775df6604c84c93a38fd9 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Mon, 19 Sep 2022 11:01:08 -0300 Subject: [PATCH 1/2] feat: Increments charts endpoint with related dashboards --- superset/charts/api.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/superset/charts/api.py b/superset/charts/api.py index 8a111b005d2c2..9fb9872048064 100644 --- a/superset/charts/api.py +++ b/superset/charts/api.py @@ -125,6 +125,8 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "owners.id", "owners.last_name", "owners.username", + "dashboards.id", + "dashboards.dashboard_title", "params", "slice_name", "thumbnail_url", @@ -164,6 +166,8 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "owners.id", "owners.last_name", "owners.username", + "dashboards.id", + "dashboards.dashboard_title", "params", "slice_name", "table.default_endpoint", @@ -198,6 +202,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]: "description", "id", "owners", + "dashboards", "slice_name", "viz_type", ] From e6b0f22bd21fa53c8a4ff0ca0989b075bf3808a3 Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" Date: Tue, 20 Sep 2022 10:36:49 -0300 Subject: [PATCH 2/2] Adds tests --- tests/integration_tests/charts/api_tests.py | 45 +++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tests/integration_tests/charts/api_tests.py b/tests/integration_tests/charts/api_tests.py index c0aaaa2c78dc4..48d04726361d9 100644 --- a/tests/integration_tests/charts/api_tests.py +++ b/tests/integration_tests/charts/api_tests.py @@ -821,6 +821,51 @@ def test_get_charts(self): data = json.loads(rv.data.decode("utf-8")) self.assertEqual(data["count"], 34) + @pytest.mark.usefixtures("load_energy_table_with_slice", "add_dashboard_to_chart") + def test_get_charts_dashboards(self): + """ + Chart API: Test get charts with related dashboards + """ + self.login(username="admin") + arguments = { + "filters": [ + {"col": "slice_name", "opr": "eq", "value": self.chart.slice_name} + ] + } + uri = f"api/v1/chart/?q={prison.dumps(arguments)}" + rv = self.get_assert_metric(uri, "get_list") + self.assertEqual(rv.status_code, 200) + data = json.loads(rv.data.decode("utf-8")) + assert data["result"][0]["dashboards"] == [ + { + "id": self.original_dashboard.id, + "dashboard_title": self.original_dashboard.dashboard_title, + } + ] + + @pytest.mark.usefixtures("load_energy_table_with_slice", "add_dashboard_to_chart") + def test_get_charts_dashboard_filter(self): + """ + Chart API: Test get charts with dashboard filter + """ + self.login(username="admin") + arguments = { + "filters": [ + { + "col": "dashboards", + "opr": "rel_m_m", + "value": self.original_dashboard.id, + } + ] + } + uri = f"api/v1/chart/?q={prison.dumps(arguments)}" + rv = self.get_assert_metric(uri, "get_list") + self.assertEqual(rv.status_code, 200) + data = json.loads(rv.data.decode("utf-8")) + result = data["result"] + assert len(result) == 1 + assert result[0]["slice_name"] == self.chart.slice_name + def test_get_charts_changed_on(self): """ Dashboard API: Test get charts changed on