mirror of
https://github.com/apache/superset.git
synced 2026-04-20 00:24:38 +00:00
fix: show error on invalid import (#14851)
* fix: show error on invalid import * Add unit test * Remove unused imports * Fix tests
This commit is contained in:
@@ -1633,9 +1633,22 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"charts/imported_chart.yaml": "Chart already exists and `overwrite=true` was not passed"
|
||||
}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing chart",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"charts/imported_chart.yaml": "Chart already exists and `overwrite=true` was not passed",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": "Issue 1010 - Superset encountered an error while running a command.",
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# import with overwrite flag
|
||||
@@ -1691,7 +1704,25 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixin):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {"metadata.yaml": {"type": ["Must be equal to Slice."]}}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing chart",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"metadata.yaml": {"type": ["Must be equal to Slice."]},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@pytest.mark.usefixtures(
|
||||
|
||||
@@ -626,6 +626,14 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
buf.seek(0)
|
||||
return buf
|
||||
|
||||
def create_invalid_dashboard_import(self):
|
||||
buf = BytesIO()
|
||||
with ZipFile(buf, "w") as bundle:
|
||||
with bundle.open("sql/dump.sql", "w") as fp:
|
||||
fp.write("CREATE TABLE foo (bar INT)".encode())
|
||||
buf.seek(0)
|
||||
return buf
|
||||
|
||||
def test_delete_dashboard(self):
|
||||
"""
|
||||
Dashboard API: Test delete
|
||||
@@ -1392,6 +1400,42 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
db.session.delete(database)
|
||||
db.session.commit()
|
||||
|
||||
def test_import_dashboard_invalid_file(self):
|
||||
"""
|
||||
Dashboard API: Test import invalid dashboard file
|
||||
"""
|
||||
self.login(username="admin")
|
||||
uri = "api/v1/dashboard/import/"
|
||||
|
||||
buf = self.create_invalid_dashboard_import()
|
||||
form_data = {
|
||||
"formData": (buf, "dashboard_export.zip"),
|
||||
}
|
||||
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 == 400
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "No valid import files were found",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_import_dashboard_v0_export(self):
|
||||
num_dashboards = db.session.query(Dashboard).count()
|
||||
|
||||
@@ -1449,9 +1493,25 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"dashboards/imported_dashboard.yaml": "Dashboard already exists and `overwrite=true` was not passed"
|
||||
}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dashboard",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"dashboards/imported_dashboard.yaml": "Dashboard already exists and `overwrite=true` was not passed",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# import with overwrite flag
|
||||
@@ -1515,7 +1575,25 @@ class TestDashboardApi(SupersetTestCase, ApiOwnersTestCaseMixin, InsertChartMixi
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {"metadata.yaml": {"type": ["Must be equal to Dashboard."]}}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dashboard",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"metadata.yaml": {"type": ["Must be equal to Dashboard."]},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered "
|
||||
"an error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_get_all_related_roles(self):
|
||||
|
||||
@@ -1208,9 +1208,25 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"databases/imported_database.yaml": "Database already exists and `overwrite=true` was not passed"
|
||||
}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": "Database already exists and `overwrite=true` was not passed",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# import with overwrite flag
|
||||
@@ -1263,7 +1279,25 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {"metadata.yaml": {"type": ["Must be equal to Database."]}}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"metadata.yaml": {"type": ["Must be equal to Database."]},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_import_database_masked_password(self):
|
||||
@@ -1300,11 +1334,27 @@ class TestDatabaseApi(SupersetTestCase):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": ["Must provide a password for the database"]
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing database",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"databases/imported_database.yaml": {
|
||||
"_schema": ["Must provide a password for the database"]
|
||||
},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered an "
|
||||
"error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_import_database_masked_password_provided(self):
|
||||
|
||||
@@ -1543,9 +1543,22 @@ class TestDatasetApi(SupersetTestCase):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {
|
||||
"datasets/imported_dataset.yaml": "Dataset already exists and `overwrite=true` was not passed"
|
||||
}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dataset",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"datasets/imported_dataset.yaml": "Dataset already exists and `overwrite=true` was not passed",
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": "Issue 1010 - Superset encountered an error while running a command.",
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
# import with overwrite flag
|
||||
@@ -1599,7 +1612,25 @@ class TestDatasetApi(SupersetTestCase):
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {
|
||||
"message": {"metadata.yaml": {"type": ["Must be equal to SqlaTable."]}}
|
||||
"errors": [
|
||||
{
|
||||
"message": "Error importing dataset",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"metadata.yaml": {"type": ["Must be equal to SqlaTable."]},
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": (
|
||||
"Issue 1010 - Superset encountered "
|
||||
"an error while running a command."
|
||||
),
|
||||
}
|
||||
],
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
def test_import_dataset_invalid_v0_validation(self):
|
||||
@@ -1628,4 +1659,20 @@ class TestDatasetApi(SupersetTestCase):
|
||||
response = json.loads(rv.data.decode("utf-8"))
|
||||
|
||||
assert rv.status_code == 422
|
||||
assert response == {"message": "Could not process entity"}
|
||||
assert response == {
|
||||
"errors": [
|
||||
{
|
||||
"message": "Could not find a valid command to import file",
|
||||
"error_type": "GENERIC_COMMAND_ERROR",
|
||||
"level": "warning",
|
||||
"extra": {
|
||||
"issue_codes": [
|
||||
{
|
||||
"code": 1010,
|
||||
"message": "Issue 1010 - Superset encountered an error while running a command.",
|
||||
}
|
||||
]
|
||||
},
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user