mirror of
https://github.com/apache/superset.git
synced 2026-04-21 00:54:44 +00:00
feat(tags): Export and Import Functionality for Superset Dashboards and Charts (#30833)
Co-authored-by: Asher Manangan <amanangan@powercosts.com>
This commit is contained in:
@@ -18,8 +18,10 @@
|
||||
|
||||
import copy
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import patch
|
||||
|
||||
import pytest
|
||||
import yaml
|
||||
from flask_appbuilder.security.sqla.models import Role, User
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlalchemy.orm.session import Session
|
||||
@@ -27,7 +29,10 @@ from sqlalchemy.orm.session import Session
|
||||
from superset import security_manager
|
||||
from superset.commands.dashboard.importers.v1.utils import import_dashboard
|
||||
from superset.commands.exceptions import ImportFailedError
|
||||
from superset.commands.importers.v1.utils import import_tag
|
||||
from superset.extensions import feature_flag_manager
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.tags.models import TaggedObject
|
||||
from superset.utils.core import override_user
|
||||
from tests.integration_tests.fixtures.importexport import dashboard_config
|
||||
|
||||
@@ -238,3 +243,43 @@ def test_import_existing_dashboard_with_permission(
|
||||
# Assert that the can write to dashboard was checked
|
||||
mock_can_access.assert_called_once_with("can_write", "Dashboard")
|
||||
mock_can_access_dashboard.assert_called_once_with(dashboard)
|
||||
|
||||
|
||||
def test_import_tag_logic_for_dashboards(session_with_schema: Session):
|
||||
contents = {
|
||||
"tags.yaml": yaml.dump(
|
||||
{"tags": [{"tag_name": "tag_1", "description": "Description for tag_1"}]}
|
||||
)
|
||||
}
|
||||
|
||||
object_id = 1
|
||||
object_type = "dashboards"
|
||||
|
||||
with patch.object(feature_flag_manager, "is_feature_enabled", return_value=True):
|
||||
new_tag_ids = import_tag(
|
||||
["tag_1"], contents, object_id, object_type, session_with_schema
|
||||
)
|
||||
assert len(new_tag_ids) > 0
|
||||
assert (
|
||||
session_with_schema.query(TaggedObject)
|
||||
.filter_by(object_id=object_id, object_type=object_type)
|
||||
.count()
|
||||
> 0
|
||||
)
|
||||
|
||||
session_with_schema.query(TaggedObject).filter_by(
|
||||
object_id=object_id, object_type=object_type
|
||||
).delete()
|
||||
session_with_schema.commit()
|
||||
|
||||
with patch.object(feature_flag_manager, "is_feature_enabled", return_value=False):
|
||||
new_tag_ids_disabled = import_tag(
|
||||
["tag_1"], contents, object_id, object_type, session_with_schema
|
||||
)
|
||||
assert len(new_tag_ids_disabled) == 0
|
||||
associated_tags = (
|
||||
session_with_schema.query(TaggedObject)
|
||||
.filter_by(object_id=object_id, object_type=object_type)
|
||||
.all()
|
||||
)
|
||||
assert len(associated_tags) == 0
|
||||
|
||||
Reference in New Issue
Block a user