From c532d790a2725d3b686e712cc164a16daaabc11f Mon Sep 17 00:00:00 2001 From: Beto Dealmeida Date: Wed, 16 Mar 2022 18:40:23 -0700 Subject: [PATCH] Fix tests --- superset/commands/importers/v1/assets.py | 7 ++++--- tests/integration_tests/commands_test.py | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/superset/commands/importers/v1/assets.py b/superset/commands/importers/v1/assets.py index 6a54438c9a63e..9f945c560af5f 100644 --- a/superset/commands/importers/v1/assets.py +++ b/superset/commands/importers/v1/assets.py @@ -101,9 +101,10 @@ def _import(session: Session, configs: Dict[str, Any]) -> None: # import charts chart_ids: Dict[str, int] = {} for file_name, config in configs.items(): - config.update(dataset_info[config["dataset_uuid"]]) - chart = import_chart(session, config, overwrite=True) - chart_ids[str(chart.uuid)] = chart.id + if file_name.startswith("charts/"): + config.update(dataset_info[config["dataset_uuid"]]) + chart = import_chart(session, config, overwrite=True) + chart_ids[str(chart.uuid)] = chart.id # store the existing relationship between dashboards and charts existing_relationships = session.execute( diff --git a/tests/integration_tests/commands_test.py b/tests/integration_tests/commands_test.py index a17cb6f84fc1f..5ff18b02a93e4 100644 --- a/tests/integration_tests/commands_test.py +++ b/tests/integration_tests/commands_test.py @@ -59,7 +59,7 @@ def test_is_valid_config(self): class TestImportAssetsCommand(SupersetTestCase): @patch("superset.dashboards.commands.importers.v1.utils.g") - def test_import_v1_dashboard(self, mock_g): + def test_import_assets(self, mock_g): """Test that we can import multiple assets""" mock_g.user = security_manager.find_user("admin") contents = { @@ -183,3 +183,20 @@ def test_import_v1_dashboard_overwrite(self, mock_g): command.run() chart = db.session.query(Slice).filter_by(uuid=chart_config["uuid"]).one() assert chart.cache_timeout == 3600 + + dashboard = ( + db.session.query(Dashboard).filter_by(uuid=dashboard_config["uuid"]).one() + ) + chart = dashboard.slices[0] + dataset = chart.table + database = dataset.database + dashboard.owners = [] + + chart.owners = [] + dataset.owners = [] + database.owners = [] + db.session.delete(dashboard) + db.session.delete(chart) + db.session.delete(dataset) + db.session.delete(database) + db.session.commit()