mirror of
https://github.com/apache/superset.git
synced 2026-04-17 07:05:04 +00:00
fix(import): Import a DB connection with expanded rows enabled (#32657)
This commit is contained in:
@@ -1103,6 +1103,11 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
assert rv.status_code == 201
|
||||
assert "sqlalchemy_form" in response["result"]["configuration_method"]
|
||||
|
||||
# Cleanup
|
||||
model = db.session.query(Database).get(response.get("id"))
|
||||
db.session.delete(model)
|
||||
db.session.commit()
|
||||
|
||||
def test_create_database_server_cert_validate(self):
|
||||
"""
|
||||
Database API: Test create server cert validation
|
||||
@@ -3153,6 +3158,59 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
]
|
||||
}
|
||||
|
||||
@mock.patch("superset.commands.database.importers.v1.utils.add_permissions")
|
||||
def test_import_database_row_expansion_enabled(self, mock_add_permissions):
|
||||
"""
|
||||
Database API: Test import database with row expansion enabled.
|
||||
"""
|
||||
self.login(ADMIN_USERNAME)
|
||||
uri = "api/v1/database/import/"
|
||||
|
||||
db_config = {
|
||||
"database_name": "DB with expand rows enabled",
|
||||
"allow_csv_upload": True,
|
||||
"allow_ctas": True,
|
||||
"allow_cvas": True,
|
||||
"allow_dml": True,
|
||||
"allow_run_async": False,
|
||||
"cache_timeout": None,
|
||||
"expose_in_sqllab": True,
|
||||
"extra": {
|
||||
"schema_options": {"expand_rows": True},
|
||||
},
|
||||
"sqlalchemy_uri": "postgresql://user:pass@host1",
|
||||
"uuid": "b8a1ccd3-779d-4ab7-8ad8-9ab119d7ff90",
|
||||
"version": "1.0.0",
|
||||
}
|
||||
|
||||
buf = BytesIO()
|
||||
with ZipFile(buf, "w") as bundle:
|
||||
with bundle.open("database_export/metadata.yaml", "w") as fp:
|
||||
fp.write(yaml.safe_dump(database_metadata_config).encode())
|
||||
with bundle.open(
|
||||
"database_export/databases/DB_with_expand_rows_enabled.yaml", "w"
|
||||
) as fp:
|
||||
fp.write(yaml.safe_dump(db_config).encode())
|
||||
buf.seek(0)
|
||||
|
||||
form_data = {
|
||||
"formData": (buf, "database_export.zip"),
|
||||
"passwords": json.dumps(
|
||||
{"databases/DB_with_expand_rows_enabled.yaml": "SECRET"}
|
||||
),
|
||||
}
|
||||
rv = self.client.post(uri, data=form_data, content_type="multipart/form-data")
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 200
|
||||
assert response == {"message": "OK"}
|
||||
|
||||
database = db.session.query(Database).filter_by(uuid=db_config["uuid"]).one()
|
||||
assert database.extra == json.dumps({"schema_options": {"expand_rows": True}})
|
||||
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
@mock.patch(
|
||||
"superset.db_engine_specs.base.BaseEngineSpec.get_function_names",
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user