fix: import should accept old keys (#17330)

* fix: import should accept old keys

* Fix lint

* Preserve V1 schema
This commit is contained in:
Beto Dealmeida
2021-11-03 11:25:30 -07:00
committed by GitHub
parent 59a6502efe
commit cb34a22684
5 changed files with 101 additions and 20 deletions

View File

@@ -107,7 +107,7 @@ class TestExportDatabasesCommand(SupersetTestCase):
metadata = yaml.safe_load(contents["databases/examples.yaml"])
assert metadata == (
{
"allow_file_upload": True,
"allow_csv_upload": True,
"allow_ctas": True,
"allow_cvas": True,
"allow_run_async": False,
@@ -305,7 +305,7 @@ class TestExportDatabasesCommand(SupersetTestCase):
"allow_run_async",
"allow_ctas",
"allow_cvas",
"allow_file_upload",
"allow_csv_upload",
"extra",
"uuid",
"version",
@@ -338,6 +338,41 @@ class TestImportDatabasesCommand(SupersetTestCase):
db.session.delete(database)
db.session.commit()
def test_import_v1_database_broken_csv_fields(self):
"""
Test that a database can be imported with broken schema.
https://github.com/apache/superset/pull/16756 renamed some fields, changing
the V1 schema. This test ensures that we can import databases that were
exported with the broken schema.
"""
broken_config = database_config.copy()
broken_config["allow_file_upload"] = broken_config.pop("allow_csv_upload")
broken_config["extra"] = {"schemas_allowed_for_file_upload": ["upload"]}
contents = {
"metadata.yaml": yaml.safe_dump(database_metadata_config),
"databases/imported_database.yaml": yaml.safe_dump(broken_config),
}
command = ImportDatabasesCommand(contents)
command.run()
database = (
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
)
assert database.allow_file_upload
assert database.allow_ctas
assert database.allow_cvas
assert not database.allow_run_async
assert database.cache_timeout is None
assert database.database_name == "imported_database"
assert database.expose_in_sqllab
assert database.extra == '{"schemas_allowed_for_file_upload": ["upload"]}'
assert database.sqlalchemy_uri == "sqlite:///test.db"
db.session.delete(database)
db.session.commit()
def test_import_v1_database_multiple(self):
"""Test that a database can be imported multiple times"""
num_databases = db.session.query(Database).count()
@@ -359,7 +394,7 @@ class TestImportDatabasesCommand(SupersetTestCase):
# update allow_file_upload to False
new_config = database_config.copy()
new_config["allow_file_upload"] = False
new_config["allow_csv_upload"] = False
contents = {
"databases/imported_database.yaml": yaml.safe_dump(new_config),
"metadata.yaml": yaml.safe_dump(database_metadata_config),