Skip to content

Commit

Permalink
Add overwrite test
Browse files Browse the repository at this point in the history
  • Loading branch information
betodealmeida committed Mar 16, 2022
1 parent 0b5981f commit df7b2e0
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/integration_tests/commands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
import copy
import json
from unittest.mock import patch

Expand All @@ -24,6 +25,7 @@
from superset.commands.importers.v1.assets import ImportAssetsCommand
from superset.commands.importers.v1.utils import is_valid_config
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from tests.integration_tests.base_tests import SupersetTestCase
from tests.integration_tests.fixtures.importexport import (
chart_config,
Expand Down Expand Up @@ -145,3 +147,34 @@ def test_import_v1_dashboard(self, mock_g):
db.session.delete(dataset)
db.session.delete(database)
db.session.commit()

@patch("superset.dashboards.commands.importers.v1.utils.g")
def test_import_v1_dashboard_overwrite(self, mock_g):
"""Test that we can import a dashboard"""
mock_g.user = security_manager.find_user("admin")

contents = {
"metadata.yaml": yaml.safe_dump(dashboard_metadata_config),
"databases/imported_database.yaml": yaml.safe_dump(database_config),
"datasets/imported_dataset.yaml": yaml.safe_dump(dataset_config),
"charts/imported_chart.yaml": yaml.safe_dump(chart_config),
"dashboards/imported_dashboard.yaml": yaml.safe_dump(dashboard_config),
}
command = ImportAssetsCommand(contents)
command.run()
chart = db.session.query(Slice).filter_by(uuid=chart_config["uuid"]).one()
assert chart.cache_timeout is None

modified_chart_config = copy.deepcopy(chart_config)
modified_chart_config["cache_timeout"] = 3600
contents = {
"metadata.yaml": yaml.safe_dump(dashboard_metadata_config),
"databases/imported_database.yaml": yaml.safe_dump(database_config),
"datasets/imported_dataset.yaml": yaml.safe_dump(dataset_config),
"charts/imported_chart.yaml": yaml.safe_dump(modified_chart_config),
"dashboards/imported_dashboard.yaml": yaml.safe_dump(dashboard_config),
}
command = ImportAssetsCommand(contents)
command.run()
chart = db.session.query(Slice).filter_by(uuid=chart_config["uuid"]).one()
assert chart.cache_timeout == 3600

0 comments on commit df7b2e0

Please sign in to comment.