chore: Clean up the examples dashboards (#26158)

This commit is contained in:
Michael S. Molina
2023-12-04 16:05:08 -03:00
committed by Michael S. Molina
parent 4cba277795
commit f4873860fc
18 changed files with 682 additions and 1349 deletions

View File

@@ -94,17 +94,11 @@ class TestExportDashboardsCommand(SupersetTestCase):
"slug": "world_health",
"uuid": str(example_dashboard.uuid),
"position": {
"CHART-36bfc934": {
"children": [],
"id": "CHART-36bfc934",
"meta": {"height": 25, "sliceName": "Region Filter", "width": 2},
"type": "CHART",
},
"CHART-37982887": {
"children": [],
"id": "CHART-37982887",
"meta": {
"height": 25,
"height": 52,
"sliceName": "World's Population",
"width": 2,
},
@@ -177,7 +171,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
"type": "COLUMN",
},
"COLUMN-fe3914b8": {
"children": ["CHART-36bfc934", "CHART-37982887"],
"children": ["CHART-37982887"],
"id": "COLUMN-fe3914b8",
"meta": {"background": "BACKGROUND_TRANSPARENT", "width": 2},
"type": "COLUMN",
@@ -293,7 +287,9 @@ class TestExportDashboardsCommand(SupersetTestCase):
mock_suffix.side_effect = (str(i) for i in itertools.count(1))
position = get_default_position("example")
chart_1 = db.session.query(Slice).filter_by(slice_name="Region Filter").one()
chart_1 = (
db.session.query(Slice).filter_by(slice_name="World's Population").one()
)
new_position = append_charts(position, {chart_1})
assert new_position == {
"DASHBOARD_VERSION_KEY": "v2",
@@ -322,7 +318,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
"meta": {
"chartId": chart_1.id,
"height": 50,
"sliceName": "Region Filter",
"sliceName": "World's Population",
"uuid": str(chart_1.uuid),
"width": 4,
},
@@ -369,7 +365,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
"meta": {
"chartId": chart_1.id,
"height": 50,
"sliceName": "Region Filter",
"sliceName": "World's Population",
"uuid": str(chart_1.uuid),
"width": 4,
},
@@ -400,7 +396,7 @@ class TestExportDashboardsCommand(SupersetTestCase):
"meta": {
"chartId": chart_1.id,
"height": 50,
"sliceName": "Region Filter",
"sliceName": "World's Population",
"uuid": str(chart_1.uuid),
"width": 4,
},

View File

@@ -33,60 +33,6 @@ from tests.integration_tests.fixtures.world_bank_dashboard import (
class TestDashboardDAO(SupersetTestCase):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_set_dash_metadata(self):
dash: Dashboard = (
db.session.query(Dashboard).filter_by(slug="world_health").first()
)
data = dash.data
positions = data["position_json"]
data.update({"positions": positions})
original_data = copy.deepcopy(data)
# add filter scopes
filter_slice = next(slc for slc in dash.slices if slc.viz_type == "filter_box")
immune_slices = [slc for slc in dash.slices if slc != filter_slice]
filter_scopes = {
str(filter_slice.id): {
"region": {
"scope": ["ROOT_ID"],
"immune": [slc.id for slc in immune_slices],
}
}
}
data.update({"filter_scopes": json.dumps(filter_scopes)})
DashboardDAO.set_dash_metadata(dash, data)
updated_metadata = json.loads(dash.json_metadata)
self.assertEqual(updated_metadata["filter_scopes"], filter_scopes)
# remove a slice and change slice ids (as copy slices)
removed_slice = immune_slices.pop()
removed_components = [
key
for (key, value) in positions.items()
if isinstance(value, dict)
and value.get("type") == "CHART"
and value["meta"]["chartId"] == removed_slice.id
]
for component_id in removed_components:
del positions[component_id]
data.update({"positions": positions})
DashboardDAO.set_dash_metadata(dash, data)
updated_metadata = json.loads(dash.json_metadata)
expected_filter_scopes = {
str(filter_slice.id): {
"region": {
"scope": ["ROOT_ID"],
"immune": [slc.id for slc in immune_slices],
}
}
}
self.assertEqual(updated_metadata["filter_scopes"], expected_filter_scopes)
# reset dash to original data
DashboardDAO.set_dash_metadata(dash, original_data)
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
@patch("superset.utils.core.g")
@patch("superset.security.manager.g")