fix: set correct schema on config import (#16041)

* fix: set correct schema on config import

* Fix lint

* Fix test

* Fix tests

* Fix another test

* Fix another test

* Fix base test

* Add helper function

* Fix examples

* Fix test

* Fix test

* Fixing more tests

(cherry picked from commit 1fbce88a46)
This commit is contained in:
Beto Dealmeida
2021-11-04 11:09:08 -07:00
committed by Elizabeth Thompson
parent 3d8ce130ba
commit 77c4f2cb11
30 changed files with 309 additions and 116 deletions

View File

@@ -43,7 +43,7 @@ from superset.dashboards.commands.importers.v0 import import_chart, import_dashb
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
from superset.utils.core import get_example_database, get_example_default_schema
from tests.integration_tests.fixtures.world_bank_dashboard import (
load_world_bank_dashboard_with_slices,
@@ -246,6 +246,7 @@ class TestImportExport(SupersetTestCase):
self.assertEqual(e_slc.datasource.schema, params["schema"])
self.assertEqual(e_slc.datasource.database.name, params["database_name"])
@unittest.skip("Schema needs to be updated")
@pytest.mark.usefixtures("load_birth_names_dashboard_with_slices")
def test_export_1_dashboard(self):
self.login("admin")
@@ -273,6 +274,7 @@ class TestImportExport(SupersetTestCase):
self.assertEqual(1, len(exported_tables))
self.assert_table_equals(self.get_table(name="birth_names"), exported_tables[0])
@unittest.skip("Schema needs to be updated")
@pytest.mark.usefixtures(
"load_world_bank_dashboard_with_slices",
"load_birth_names_dashboard_with_slices",
@@ -317,7 +319,9 @@ class TestImportExport(SupersetTestCase):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_import_1_slice(self):
expected_slice = self.create_slice("Import Me", id=10001)
expected_slice = self.create_slice(
"Import Me", id=10001, schema=get_example_default_schema()
)
slc_id = import_chart(expected_slice, None, import_time=1989)
slc = self.get_slice(slc_id)
self.assertEqual(slc.datasource.perm, slc.perm)
@@ -328,10 +332,15 @@ class TestImportExport(SupersetTestCase):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_import_2_slices_for_same_table(self):
schema = get_example_default_schema()
table_id = self.get_table(name="wb_health_population").id
slc_1 = self.create_slice("Import Me 1", ds_id=table_id, id=10002)
slc_1 = self.create_slice(
"Import Me 1", ds_id=table_id, id=10002, schema=schema
)
slc_id_1 = import_chart(slc_1, None)
slc_2 = self.create_slice("Import Me 2", ds_id=table_id, id=10003)
slc_2 = self.create_slice(
"Import Me 2", ds_id=table_id, id=10003, schema=schema
)
slc_id_2 = import_chart(slc_2, None)
imported_slc_1 = self.get_slice(slc_id_1)
@@ -345,11 +354,12 @@ class TestImportExport(SupersetTestCase):
self.assertEqual(imported_slc_2.datasource.perm, imported_slc_2.perm)
def test_import_slices_override(self):
slc = self.create_slice("Import Me New", id=10005)
schema = get_example_default_schema()
slc = self.create_slice("Import Me New", id=10005, schema=schema)
slc_1_id = import_chart(slc, None, import_time=1990)
slc.slice_name = "Import Me New"
imported_slc_1 = self.get_slice(slc_1_id)
slc_2 = self.create_slice("Import Me New", id=10005)
slc_2 = self.create_slice("Import Me New", id=10005, schema=schema)
slc_2_id = import_chart(slc_2, imported_slc_1, import_time=1990)
self.assertEqual(slc_1_id, slc_2_id)
imported_slc_2 = self.get_slice(slc_2_id)
@@ -363,7 +373,9 @@ class TestImportExport(SupersetTestCase):
@pytest.mark.usefixtures("load_world_bank_dashboard_with_slices")
def test_import_dashboard_1_slice(self):
slc = self.create_slice("health_slc", id=10006)
slc = self.create_slice(
"health_slc", id=10006, schema=get_example_default_schema()
)
dash_with_1_slice = self.create_dashboard(
"dash_with_1_slice", slcs=[slc], id=10002
)
@@ -405,8 +417,13 @@ class TestImportExport(SupersetTestCase):
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_import_dashboard_2_slices(self):
e_slc = self.create_slice("e_slc", id=10007, table_name="energy_usage")
b_slc = self.create_slice("b_slc", id=10008, table_name="birth_names")
schema = get_example_default_schema()
e_slc = self.create_slice(
"e_slc", id=10007, table_name="energy_usage", schema=schema
)
b_slc = self.create_slice(
"b_slc", id=10008, table_name="birth_names", schema=schema
)
dash_with_2_slices = self.create_dashboard(
"dash_with_2_slices", slcs=[e_slc, b_slc], id=10003
)
@@ -457,17 +474,28 @@ class TestImportExport(SupersetTestCase):
@pytest.mark.usefixtures("load_energy_table_with_slice")
def test_import_override_dashboard_2_slices(self):
e_slc = self.create_slice("e_slc", id=10009, table_name="energy_usage")
b_slc = self.create_slice("b_slc", id=10010, table_name="birth_names")
schema = get_example_default_schema()
e_slc = self.create_slice(
"e_slc", id=10009, table_name="energy_usage", schema=schema
)
b_slc = self.create_slice(
"b_slc", id=10010, table_name="birth_names", schema=schema
)
dash_to_import = self.create_dashboard(
"override_dashboard", slcs=[e_slc, b_slc], id=10004
)
imported_dash_id_1 = import_dashboard(dash_to_import, import_time=1992)
# create new instances of the slices
e_slc = self.create_slice("e_slc", id=10009, table_name="energy_usage")
b_slc = self.create_slice("b_slc", id=10010, table_name="birth_names")
c_slc = self.create_slice("c_slc", id=10011, table_name="birth_names")
e_slc = self.create_slice(
"e_slc", id=10009, table_name="energy_usage", schema=schema
)
b_slc = self.create_slice(
"b_slc", id=10010, table_name="birth_names", schema=schema
)
c_slc = self.create_slice(
"c_slc", id=10011, table_name="birth_names", schema=schema
)
dash_to_import_override = self.create_dashboard(
"override_dashboard_new", slcs=[e_slc, b_slc, c_slc], id=10004
)
@@ -549,7 +577,9 @@ class TestImportExport(SupersetTestCase):
self.assertEqual(imported_slc.owners, [gamma_user])
def _create_dashboard_for_import(self, id_=10100):
slc = self.create_slice("health_slc" + str(id_), id=id_ + 1)
slc = self.create_slice(
"health_slc" + str(id_), id=id_ + 1, schema=get_example_default_schema()
)
dash_with_1_slice = self.create_dashboard(
"dash_with_1_slice" + str(id_), slcs=[slc], id=id_ + 2
)
@@ -572,15 +602,21 @@ class TestImportExport(SupersetTestCase):
return dash_with_1_slice
def test_import_table_no_metadata(self):
schema = get_example_default_schema()
db_id = get_example_database().id
table = self.create_table("pure_table", id=10001)
table = self.create_table("pure_table", id=10001, schema=schema)
imported_id = import_dataset(table, db_id, import_time=1989)
imported = self.get_table_by_id(imported_id)
self.assert_table_equals(table, imported)
def test_import_table_1_col_1_met(self):
schema = get_example_default_schema()
table = self.create_table(
"table_1_col_1_met", id=10002, cols_names=["col1"], metric_names=["metric1"]
"table_1_col_1_met",
id=10002,
cols_names=["col1"],
metric_names=["metric1"],
schema=schema,
)
db_id = get_example_database().id
imported_id = import_dataset(table, db_id, import_time=1990)
@@ -592,11 +628,13 @@ class TestImportExport(SupersetTestCase):
)
def test_import_table_2_col_2_met(self):
schema = get_example_default_schema()
table = self.create_table(
"table_2_col_2_met",
id=10003,
cols_names=["c1", "c2"],
metric_names=["m1", "m2"],
schema=schema,
)
db_id = get_example_database().id
imported_id = import_dataset(table, db_id, import_time=1991)
@@ -605,8 +643,13 @@ class TestImportExport(SupersetTestCase):
self.assert_table_equals(table, imported)
def test_import_table_override(self):
schema = get_example_default_schema()
table = self.create_table(
"table_override", id=10003, cols_names=["col1"], metric_names=["m1"]
"table_override",
id=10003,
cols_names=["col1"],
metric_names=["m1"],
schema=schema,
)
db_id = get_example_database().id
imported_id = import_dataset(table, db_id, import_time=1991)
@@ -616,6 +659,7 @@ class TestImportExport(SupersetTestCase):
id=10003,
cols_names=["new_col1", "col2", "col3"],
metric_names=["new_metric1"],
schema=schema,
)
imported_over_id = import_dataset(table_over, db_id, import_time=1992)
@@ -626,15 +670,18 @@ class TestImportExport(SupersetTestCase):
id=10003,
metric_names=["new_metric1", "m1"],
cols_names=["col1", "new_col1", "col2", "col3"],
schema=schema,
)
self.assert_table_equals(expected_table, imported_over)
def test_import_table_override_identical(self):
schema = get_example_default_schema()
table = self.create_table(
"copy_cat",
id=10004,
cols_names=["new_col1", "col2", "col3"],
metric_names=["new_metric1"],
schema=schema,
)
db_id = get_example_database().id
imported_id = import_dataset(table, db_id, import_time=1993)
@@ -644,6 +691,7 @@ class TestImportExport(SupersetTestCase):
id=10004,
cols_names=["new_col1", "col2", "col3"],
metric_names=["new_metric1"],
schema=schema,
)
imported_id_copy = import_dataset(copy_table, db_id, import_time=1994)