mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
chore: consolidate datasource import logic (#11533)
* Consolidate dash import logic * WIP * Add license * Fix lint * Retrigger tests * Fix lint
This commit is contained in:
@@ -33,6 +33,7 @@ from superset.connectors.druid.models import (
|
||||
)
|
||||
from superset.connectors.sqla.models import SqlaTable, SqlMetric, TableColumn
|
||||
from superset.dashboards.commands.importers.v0 import import_chart, import_dashboard
|
||||
from superset.datasets.commands.importers.v0 import import_dataset
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils.core import get_example_database
|
||||
@@ -567,7 +568,7 @@ class TestImportExport(SupersetTestCase):
|
||||
def test_import_table_no_metadata(self):
|
||||
db_id = get_example_database().id
|
||||
table = self.create_table("pure_table", id=10001)
|
||||
imported_id = SqlaTable.import_obj(table, db_id, import_time=1989)
|
||||
imported_id = import_dataset(table, db_id, import_time=1989)
|
||||
imported = self.get_table_by_id(imported_id)
|
||||
self.assert_table_equals(table, imported)
|
||||
|
||||
@@ -576,7 +577,7 @@ class TestImportExport(SupersetTestCase):
|
||||
"table_1_col_1_met", id=10002, cols_names=["col1"], metric_names=["metric1"]
|
||||
)
|
||||
db_id = get_example_database().id
|
||||
imported_id = SqlaTable.import_obj(table, db_id, import_time=1990)
|
||||
imported_id = import_dataset(table, db_id, import_time=1990)
|
||||
imported = self.get_table_by_id(imported_id)
|
||||
self.assert_table_equals(table, imported)
|
||||
self.assertEqual(
|
||||
@@ -592,7 +593,7 @@ class TestImportExport(SupersetTestCase):
|
||||
metric_names=["m1", "m2"],
|
||||
)
|
||||
db_id = get_example_database().id
|
||||
imported_id = SqlaTable.import_obj(table, db_id, import_time=1991)
|
||||
imported_id = import_dataset(table, db_id, import_time=1991)
|
||||
|
||||
imported = self.get_table_by_id(imported_id)
|
||||
self.assert_table_equals(table, imported)
|
||||
@@ -602,7 +603,7 @@ class TestImportExport(SupersetTestCase):
|
||||
"table_override", id=10003, cols_names=["col1"], metric_names=["m1"]
|
||||
)
|
||||
db_id = get_example_database().id
|
||||
imported_id = SqlaTable.import_obj(table, db_id, import_time=1991)
|
||||
imported_id = import_dataset(table, db_id, import_time=1991)
|
||||
|
||||
table_over = self.create_table(
|
||||
"table_override",
|
||||
@@ -610,7 +611,7 @@ class TestImportExport(SupersetTestCase):
|
||||
cols_names=["new_col1", "col2", "col3"],
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
imported_over_id = SqlaTable.import_obj(table_over, db_id, import_time=1992)
|
||||
imported_over_id = import_dataset(table_over, db_id, import_time=1992)
|
||||
|
||||
imported_over = self.get_table_by_id(imported_over_id)
|
||||
self.assertEqual(imported_id, imported_over.id)
|
||||
@@ -630,7 +631,7 @@ class TestImportExport(SupersetTestCase):
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
db_id = get_example_database().id
|
||||
imported_id = SqlaTable.import_obj(table, db_id, import_time=1993)
|
||||
imported_id = import_dataset(table, db_id, import_time=1993)
|
||||
|
||||
copy_table = self.create_table(
|
||||
"copy_cat",
|
||||
@@ -638,14 +639,14 @@ class TestImportExport(SupersetTestCase):
|
||||
cols_names=["new_col1", "col2", "col3"],
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
imported_id_copy = SqlaTable.import_obj(copy_table, db_id, import_time=1994)
|
||||
imported_id_copy = import_dataset(copy_table, db_id, import_time=1994)
|
||||
|
||||
self.assertEqual(imported_id, imported_id_copy)
|
||||
self.assert_table_equals(copy_table, self.get_table_by_id(imported_id))
|
||||
|
||||
def test_import_druid_no_metadata(self):
|
||||
datasource = self.create_druid_datasource("pure_druid", id=10001)
|
||||
imported_id = DruidDatasource.import_obj(datasource, import_time=1989)
|
||||
imported_id = import_dataset(datasource, import_time=1989)
|
||||
imported = self.get_datasource(imported_id)
|
||||
self.assert_datasource_equals(datasource, imported)
|
||||
|
||||
@@ -653,7 +654,7 @@ class TestImportExport(SupersetTestCase):
|
||||
datasource = self.create_druid_datasource(
|
||||
"druid_1_col_1_met", id=10002, cols_names=["col1"], metric_names=["metric1"]
|
||||
)
|
||||
imported_id = DruidDatasource.import_obj(datasource, import_time=1990)
|
||||
imported_id = import_dataset(datasource, import_time=1990)
|
||||
imported = self.get_datasource(imported_id)
|
||||
self.assert_datasource_equals(datasource, imported)
|
||||
self.assertEqual(
|
||||
@@ -668,7 +669,7 @@ class TestImportExport(SupersetTestCase):
|
||||
cols_names=["c1", "c2"],
|
||||
metric_names=["m1", "m2"],
|
||||
)
|
||||
imported_id = DruidDatasource.import_obj(datasource, import_time=1991)
|
||||
imported_id = import_dataset(datasource, import_time=1991)
|
||||
imported = self.get_datasource(imported_id)
|
||||
self.assert_datasource_equals(datasource, imported)
|
||||
|
||||
@@ -676,14 +677,14 @@ class TestImportExport(SupersetTestCase):
|
||||
datasource = self.create_druid_datasource(
|
||||
"druid_override", id=10004, cols_names=["col1"], metric_names=["m1"]
|
||||
)
|
||||
imported_id = DruidDatasource.import_obj(datasource, import_time=1991)
|
||||
imported_id = import_dataset(datasource, import_time=1991)
|
||||
table_over = self.create_druid_datasource(
|
||||
"druid_override",
|
||||
id=10004,
|
||||
cols_names=["new_col1", "col2", "col3"],
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
imported_over_id = DruidDatasource.import_obj(table_over, import_time=1992)
|
||||
imported_over_id = import_dataset(table_over, import_time=1992)
|
||||
|
||||
imported_over = self.get_datasource(imported_over_id)
|
||||
self.assertEqual(imported_id, imported_over.id)
|
||||
@@ -702,7 +703,7 @@ class TestImportExport(SupersetTestCase):
|
||||
cols_names=["new_col1", "col2", "col3"],
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
imported_id = DruidDatasource.import_obj(datasource, import_time=1993)
|
||||
imported_id = import_dataset(datasource, import_time=1993)
|
||||
|
||||
copy_datasource = self.create_druid_datasource(
|
||||
"copy_cat",
|
||||
@@ -710,7 +711,7 @@ class TestImportExport(SupersetTestCase):
|
||||
cols_names=["new_col1", "col2", "col3"],
|
||||
metric_names=["new_metric1"],
|
||||
)
|
||||
imported_id_copy = DruidDatasource.import_obj(copy_datasource, import_time=1994)
|
||||
imported_id_copy = import_dataset(copy_datasource, import_time=1994)
|
||||
|
||||
self.assertEqual(imported_id, imported_id_copy)
|
||||
self.assert_datasource_equals(copy_datasource, self.get_datasource(imported_id))
|
||||
|
||||
Reference in New Issue
Block a user