feat: Dashboard tabs api endpoint (#27962)

This commit is contained in:
Jack
2024-06-20 11:40:54 -05:00
committed by GitHub
parent 70f6f5f3ef
commit a5355d86fc
6 changed files with 308 additions and 1 deletions

View File

@@ -918,6 +918,185 @@ class TestDashboardApi(ApiOwnersTestCaseMixin, InsertChartMixin, SupersetTestCas
for key, value in expected_results[idx].items():
assert response_item[key] == value
def test_get_dashboard_tabs(self):
"""
Dashboard API: Test get dashboard tabs
"""
position_data = {
"GRID_ID": {"children": [], "id": "GRID_ID", "type": "GRID"},
"ROOT_ID": {
"children": ["TABS-tDGEcwZ82u"],
"id": "ROOT_ID",
"type": "ROOT",
},
"TAB-0TkqQRxzg7": {
"children": [],
"id": "TAB-0TkqQRxzg7",
"meta": {"text": "P2 - T1"},
"type": "TAB",
},
"TAB-1iG_yOlKA2": {
"children": [],
"id": "TAB-1iG_yOlKA2",
"meta": {"text": "P1 - T1"},
"type": "TAB",
},
"TAB-2dgADEurF": {
"children": ["TABS-LsyXZWG2rk"],
"id": "TAB-2dgADEurF",
"meta": {"text": "P1 - T2"},
"type": "TAB",
},
"TAB-BJIt5SdCx3": {
"children": [],
"id": "TAB-BJIt5SdCx3",
"meta": {"text": "P1 - T2 - T1"},
"type": "TAB",
},
"TAB-CjZlNL5Uz": {
"children": ["TABS-Ji_K1ZBE0M"],
"id": "TAB-CjZlNL5Uz",
"meta": {"text": "Parent Tab 2"},
"type": "TAB",
},
"TAB-Nct5fiHtn": {
"children": [],
"id": "TAB-Nct5fiHtn",
"meta": {"text": "P1 - T2 - T3"},
"type": "TAB",
},
"TAB-PumuDkWKq": {
"children": [],
"id": "TAB-PumuDkWKq",
"meta": {"text": "P2 - T2"},
"type": "TAB",
},
"TAB-hyTv5L7zz": {
"children": [],
"id": "TAB-hyTv5L7zz",
"meta": {"text": "P1 - T2 - T2"},
"type": "TAB",
},
"TAB-qL7fSzr3jl": {
"children": ["TABS-N8ODUqp2sE"],
"id": "TAB-qL7fSzr3jl",
"meta": {"text": "Parent Tab 1"},
"type": "TAB",
},
"TABS-Ji_K1ZBE0M": {
"children": ["TAB-0TkqQRxzg7", "TAB-PumuDkWKq"],
"id": "TABS-Ji_K1ZBE0M",
"meta": {},
"type": "TABS",
},
"TABS-LsyXZWG2rk": {
"children": ["TAB-BJIt5SdCx3", "TAB-hyTv5L7zz", "TAB-Nct5fiHtn"],
"id": "TABS-LsyXZWG2rk",
"meta": {},
"type": "TABS",
},
"TABS-N8ODUqp2sE": {
"children": ["TAB-1iG_yOlKA2", "TAB-2dgADEurF"],
"id": "TABS-N8ODUqp2sE",
"meta": {},
"type": "TABS",
},
"TABS-tDGEcwZ82u": {
"children": ["TAB-qL7fSzr3jl", "TAB-CjZlNL5Uz"],
"id": "TABS-tDGEcwZ82u",
"meta": {},
"type": "TABS",
},
}
admin_id = self.get_user("admin").id
dashboard = self.insert_dashboard(
"title", "slug", [admin_id], position_json=json.dumps(position_data)
)
self.login(ADMIN_USERNAME)
uri = f"api/v1/dashboard/{dashboard.id}/tabs"
rv = self.get_assert_metric(uri, "get_tabs")
response = json.loads(rv.data.decode("utf-8"))
expected_response = {
"result": {
"all_tabs": {
"TAB-0TkqQRxzg7": "P2 - T1",
"TAB-1iG_yOlKA2": "P1 - T1",
"TAB-2dgADEurF": "P1 - T2",
"TAB-BJIt5SdCx3": "P1 - T2 - T1",
"TAB-CjZlNL5Uz": "Parent Tab 2",
"TAB-Nct5fiHtn": "P1 - T2 - T3",
"TAB-PumuDkWKq": "P2 - T2",
"TAB-hyTv5L7zz": "P1 - T2 - T2",
"TAB-qL7fSzr3jl": "Parent Tab 1",
},
"tab_tree": [
{
"children": [
{
"children": [],
"title": "P1 - T1",
"value": "TAB-1iG_yOlKA2",
},
{
"children": [
{
"children": [],
"title": "P1 - T2 - T1",
"value": "TAB-BJIt5SdCx3",
},
{
"children": [],
"title": "P1 - T2 - T2",
"value": "TAB-hyTv5L7zz",
},
{
"children": [],
"title": "P1 - T2 - T3",
"value": "TAB-Nct5fiHtn",
},
],
"title": "P1 - T2",
"value": "TAB-2dgADEurF",
},
],
"title": "Parent Tab 1",
"value": "TAB-qL7fSzr3jl",
},
{
"children": [
{
"children": [],
"title": "P2 - T1",
"value": "TAB-0TkqQRxzg7",
},
{
"children": [],
"title": "P2 - T2",
"value": "TAB-PumuDkWKq",
},
],
"title": "Parent Tab 2",
"value": "TAB-CjZlNL5Uz",
},
],
}
}
self.assertEqual(rv.status_code, 200)
self.assertEqual(response, expected_response)
db.session.delete(dashboard)
db.session.commit()
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_get_dashboard_tabs_not_found(self):
"""
Dashboard API: Test get dashboard tabs not found
"""
bad_id = self.get_nonexistent_numeric_id(Dashboard)
self.login(ADMIN_USERNAME)
uri = f"api/v1/dashboard/{bad_id}/tabs"
rv = self.get_assert_metric(uri, "get_tabs")
self.assertEqual(rv.status_code, 404)
def create_dashboard_import(self):
buf = BytesIO()
with ZipFile(buf, "w") as bundle: