Skip to content

Commit

Permalink
tests passing
Browse files Browse the repository at this point in the history
  • Loading branch information
AAfghahi committed Apr 8, 2021
1 parent b2ec820 commit 710608d
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 12 deletions.
1 change: 1 addition & 0 deletions superset/commands/importers/v1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,5 @@ def validate(self) -> None:
if exceptions:
exception = CommandInvalidError(f"Error importing {self.model_name}")
exception.add_list(exceptions)
print(exceptions)
raise exception
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
from superset.commands.importers.v1 import ImportModelsCommand
from superset.connectors.sqla.models import SqlaTable
from superset.databases.commands.importers.v1.utils import import_database
from superset.datasets.commands.importers.v1.utils import import_dataset
from superset.datasets.schemas import ImportV1DatasetSchema
from superset.databases.schemas import ImportV1DatabaseSchema
from superset.queries.saved_queries.commands.exceptions import SavedQueryImportError
from superset.queries.saved_queries.commands.importers.v1.utils import (
import_saved_query,
Expand All @@ -40,7 +39,7 @@ class ImportSavedQueriesCommand(ImportModelsCommand):
model_name = "saved_queries"
prefix = "queries/"
schemas: Dict[str, Schema] = {
"datasets/": ImportV1DatasetSchema(),
"databases/": ImportV1DatabaseSchema(),
"queries/": ImportV1SavedQuerySchema(),
}
import_error = SavedQueryImportError
Expand Down
2 changes: 0 additions & 2 deletions tests/queries/saved_queries/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -790,8 +790,6 @@ def test_import_saved_queries(self):
)
assert database.database_name == "imported_database"

assert len(database.tables) == 1

saved_query = (
db.session.query(SavedQuery)
.filter_by(uuid=saved_queries_config["uuid"])
Expand Down
13 changes: 6 additions & 7 deletions tests/queries/saved_queries/commands_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ def test_import_v1_saved_queries(self):
.filter_by(uuid=saved_queries_config["uuid"])
.one()
)

assert saved_query.schema == "public"

database = (
Expand All @@ -161,11 +162,9 @@ def test_import_v1_saved_queries_multiple(self):
command.run()
command.run()
database = (
db.session.query(SavedQuery).filter_by(uuid=database_config["uuid"]).one()
)
saved_query = (
db.session.query(SavedQuery).filter_by(datasource_id=database.id).all()
db.session.query(Database).filter_by(uuid=database_config["uuid"]).one()
)
saved_query = db.session.query(SavedQuery).filter_by(db_id=database.id).all()
assert len(saved_query) == 1

db.session.delete(saved_query[0])
Expand Down Expand Up @@ -195,14 +194,14 @@ def test_import_v1_saved_queries_validation(self):
command = ImportSavedQueriesCommand(contents)
with pytest.raises(IncorrectVersionError) as excinfo:
command.run()
assert str(excinfo.value) == "Must be equal to 1.0.0"
assert str(excinfo.value) == "Must be equal to 1.0.0."

# type should be a SavedQuery
contents["metadata.yaml"] = yaml.safe_dump(database_metadata_config)
command = ImportSavedQueriesCommand(contents)
with pytest.raises(CommandInvalidError) as excinfo:
command.run()
assert str(excinfo.value) == "Error importing saved query."
assert str(excinfo.value) == "Error importing saved_queries"
assert excinfo.value.normalized_messages() == {
"metadata.yaml": {"type": ["Must be equal to SavedQuery."]}
}
Expand All @@ -215,7 +214,7 @@ def test_import_v1_saved_queries_validation(self):
command = ImportSavedQueriesCommand(contents)
with pytest.raises(CommandInvalidError) as excinfo:
command.run()
assert str(excinfo.value) == "Error importing saved query."
assert str(excinfo.value) == "Error importing saved_queries"
assert excinfo.value.normalized_messages() == {
"databases/imported_database.yaml": {
"database_name": ["Missing data for required field."],
Expand Down

0 comments on commit 710608d

Please sign in to comment.