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

feat: Increments charts endpoint with related dashboards #21518

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
5 changes: 5 additions & 0 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -198,6 +202,7 @@ def ensure_thumbnails_enabled(self) -> Optional[Response]:
"description",
"id",
"owners",
"dashboards",
"slice_name",
"viz_type",
]
Expand Down
45 changes: 45 additions & 0 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down