mirror of https://github.com/apache/superset.git
Merge 0c9978d635
into f5843fe588
This commit is contained in:
commit
955fcf7301
|
@ -76,7 +76,7 @@ class CreateCustomTagWithRelationshipsCommand(CreateMixin, BaseCommand):
|
|||
|
||||
try:
|
||||
tag_name = self._properties["name"]
|
||||
tag = TagDAO.get_by_name(tag_name.strip(), TagType.custom)
|
||||
tag = TagDAO.get_by_name(tag_name.strip(), TagType.CUSTOM)
|
||||
TagDAO.create_tag_relationship(
|
||||
objects_to_tag=self._properties.get("objects_to_tag", []),
|
||||
tag=tag,
|
||||
|
|
|
@ -38,10 +38,10 @@ def to_object_type(object_type: Union[ObjectType, int, str]) -> Optional[ObjectT
|
|||
def to_object_model(
|
||||
object_type: ObjectType, object_id: int
|
||||
) -> Optional[Union[Dashboard, SavedQuery, Slice]]:
|
||||
if ObjectType.dashboard == object_type:
|
||||
if ObjectType.DASHBOARD == object_type:
|
||||
return DashboardDAO.find_by_id(object_id)
|
||||
if ObjectType.query == object_type:
|
||||
if ObjectType.QUERY == object_type:
|
||||
return SavedQueryDAO.find_by_id(object_id)
|
||||
if ObjectType.chart == object_type:
|
||||
if ObjectType.CHART == object_type:
|
||||
return ChartDAO.find_by_id(object_id)
|
||||
return None
|
||||
|
|
|
@ -35,7 +35,7 @@ def add_types_to_charts(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
slices.c.id.label("object_id"),
|
||||
literal(ObjectType.chart.name).label("object_type"),
|
||||
literal(ObjectType.CHART.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -67,7 +67,7 @@ def add_types_to_dashboards(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
dashboard_table.c.id.label("object_id"),
|
||||
literal(ObjectType.dashboard.name).label("object_type"),
|
||||
literal(ObjectType.DASHBOARD.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -99,7 +99,7 @@ def add_types_to_saved_queries(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
saved_query.c.id.label("object_id"),
|
||||
literal(ObjectType.query.name).label("object_type"),
|
||||
literal(ObjectType.QUERY.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -131,7 +131,7 @@ def add_types_to_datasets(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
tables.c.id.label("object_id"),
|
||||
literal(ObjectType.dataset.name).label("object_type"),
|
||||
literal(ObjectType.DATASET.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -223,7 +223,7 @@ def add_types(metadata: MetaData) -> None:
|
|||
insert = tag.insert()
|
||||
for type_ in ObjectType.__members__:
|
||||
with contextlib.suppress(IntegrityError): # already exists
|
||||
db.session.execute(insert, name=f"type:{type_}", type=TagType.type)
|
||||
db.session.execute(insert, name=f"type:{type_}", type=TagType.TYPE)
|
||||
|
||||
add_types_to_charts(metadata, tag, tagged_object, columns)
|
||||
add_types_to_dashboards(metadata, tag, tagged_object, columns)
|
||||
|
@ -241,7 +241,7 @@ def add_owners_to_charts(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
slices.c.id.label("object_id"),
|
||||
literal(ObjectType.chart.name).label("object_type"),
|
||||
literal(ObjectType.CHART.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -277,7 +277,7 @@ def add_owners_to_dashboards(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
dashboard_table.c.id.label("object_id"),
|
||||
literal(ObjectType.dashboard.name).label("object_type"),
|
||||
literal(ObjectType.DASHBOARD.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -313,7 +313,7 @@ def add_owners_to_saved_queries(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
saved_query.c.id.label("object_id"),
|
||||
literal(ObjectType.query.name).label("object_type"),
|
||||
literal(ObjectType.QUERY.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -349,7 +349,7 @@ def add_owners_to_datasets(
|
|||
[
|
||||
tag.c.id.label("tag_id"),
|
||||
tables.c.id.label("object_id"),
|
||||
literal(ObjectType.dataset.name).label("object_type"),
|
||||
literal(ObjectType.DATASET.name).label("object_type"),
|
||||
]
|
||||
)
|
||||
.select_from(
|
||||
|
@ -444,7 +444,7 @@ def add_owners(metadata: MetaData) -> None:
|
|||
insert = tag.insert()
|
||||
for (id_,) in db.session.execute(ids):
|
||||
with contextlib.suppress(IntegrityError): # already exists
|
||||
db.session.execute(insert, name=f"owner:{id_}", type=TagType.owner)
|
||||
db.session.execute(insert, name=f"owner:{id_}", type=TagType.OWNER)
|
||||
add_owners_to_charts(metadata, tag, tagged_object, columns)
|
||||
add_owners_to_dashboards(metadata, tag, tagged_object, columns)
|
||||
add_owners_to_saved_queries(metadata, tag, tagged_object, columns)
|
||||
|
@ -482,7 +482,7 @@ def add_favorites(metadata: MetaData) -> None:
|
|||
insert = tag.insert()
|
||||
for (id_,) in db.session.execute(ids):
|
||||
with contextlib.suppress(IntegrityError): # already exists
|
||||
db.session.execute(insert, name=f"favorited_by:{id_}", type=TagType.type)
|
||||
db.session.execute(insert, name=f"favorited_by:{id_}", type=TagType.TYPE)
|
||||
favstars = (
|
||||
select(
|
||||
[
|
||||
|
|
|
@ -56,7 +56,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
clean_tag_names: set[str] = {tag.strip() for tag in tag_names}
|
||||
|
||||
for name in clean_tag_names:
|
||||
type_ = TagType.custom
|
||||
type_ = TagType.CUSTOM
|
||||
tag = TagDAO.get_by_name(name, type_)
|
||||
tagged_objects.append(
|
||||
TaggedObject(object_id=object_id, object_type=object_type, tag=tag)
|
||||
|
@ -131,7 +131,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
raise DAODeleteFailedError(exception=ex) from ex
|
||||
|
||||
@staticmethod
|
||||
def get_by_name(name: str, type_: TagType = TagType.custom) -> Tag:
|
||||
def get_by_name(name: str, type_: TagType = TagType.CUSTOM) -> Tag:
|
||||
"""
|
||||
returns a tag if one exists by that name, none otherwise.
|
||||
important!: Creates a tag by that name if the tag is not found.
|
||||
|
@ -196,7 +196,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
TaggedObject,
|
||||
and_(
|
||||
TaggedObject.object_id == Dashboard.id,
|
||||
TaggedObject.object_type == ObjectType.dashboard,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD,
|
||||
),
|
||||
)
|
||||
.join(Tag, TaggedObject.tag_id == Tag.id)
|
||||
|
@ -206,7 +206,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
results.extend(
|
||||
{
|
||||
"id": obj.id,
|
||||
"type": ObjectType.dashboard.name,
|
||||
"type": ObjectType.DASHBOARD.name,
|
||||
"name": obj.dashboard_title,
|
||||
"url": obj.url,
|
||||
"changed_on": obj.changed_on,
|
||||
|
@ -226,7 +226,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
TaggedObject,
|
||||
and_(
|
||||
TaggedObject.object_id == Slice.id,
|
||||
TaggedObject.object_type == ObjectType.chart,
|
||||
TaggedObject.object_type == ObjectType.CHART,
|
||||
),
|
||||
)
|
||||
.join(Tag, TaggedObject.tag_id == Tag.id)
|
||||
|
@ -235,7 +235,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
results.extend(
|
||||
{
|
||||
"id": obj.id,
|
||||
"type": ObjectType.chart.name,
|
||||
"type": ObjectType.CHART.name,
|
||||
"name": obj.slice_name,
|
||||
"url": obj.url,
|
||||
"changed_on": obj.changed_on,
|
||||
|
@ -255,7 +255,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
TaggedObject,
|
||||
and_(
|
||||
TaggedObject.object_id == SavedQuery.id,
|
||||
TaggedObject.object_type == ObjectType.query,
|
||||
TaggedObject.object_type == ObjectType.QUERY,
|
||||
),
|
||||
)
|
||||
.join(Tag, TaggedObject.tag_id == Tag.id)
|
||||
|
@ -264,7 +264,7 @@ class TagDAO(BaseDAO[Tag]):
|
|||
results.extend(
|
||||
{
|
||||
"id": obj.id,
|
||||
"type": ObjectType.query.name,
|
||||
"type": ObjectType.QUERY.name,
|
||||
"name": obj.label,
|
||||
"url": obj.url(),
|
||||
"changed_on": obj.changed_on,
|
||||
|
|
|
@ -28,10 +28,10 @@ down_revision = "59a1450b3c10"
|
|||
|
||||
class ObjectType(enum.Enum):
|
||||
# pylint: disable=invalid-name
|
||||
query = 1
|
||||
chart = 2
|
||||
dashboard = 3
|
||||
dataset = 4
|
||||
QUERY = 1
|
||||
CHART = 2
|
||||
DASHBOARD = 3
|
||||
DATASET = 4
|
||||
|
||||
|
||||
# Define the tagged_object table structure
|
||||
|
|
|
@ -33,7 +33,7 @@ class UserCreatedTagTypeFilter(BaseFilter): # pylint: disable=too-few-public-me
|
|||
|
||||
def apply(self, query: Query, value: bool) -> Query:
|
||||
if value:
|
||||
return query.filter(Tag.type == TagType.custom)
|
||||
return query.filter(Tag.type == TagType.CUSTOM)
|
||||
if value is False:
|
||||
return query.filter(Tag.type != TagType.custom)
|
||||
return query.filter(Tag.type != TagType.CUSTOM)
|
||||
return query
|
||||
|
|
|
@ -68,22 +68,22 @@ class TagType(enum.Enum):
|
|||
|
||||
# pylint: disable=invalid-name
|
||||
# explicit tags, added manually by the owner
|
||||
custom = 1
|
||||
CUSTOM = 1
|
||||
|
||||
# implicit tags, generated automatically
|
||||
type = 2
|
||||
owner = 3
|
||||
favorited_by = 4
|
||||
TYPE = 2
|
||||
OWNER = 3
|
||||
FAVORITED_BY = 4
|
||||
|
||||
|
||||
class ObjectType(enum.Enum):
|
||||
"""Object types."""
|
||||
|
||||
# pylint: disable=invalid-name
|
||||
query = 1
|
||||
chart = 2
|
||||
dashboard = 3
|
||||
dataset = 4
|
||||
QUERY = 1
|
||||
CHART = 2
|
||||
DASHBOARD = 3
|
||||
DATASET = 4
|
||||
|
||||
|
||||
class Tag(Model, AuditMixinNullable):
|
||||
|
@ -145,10 +145,10 @@ def get_tag(
|
|||
|
||||
def get_object_type(class_name: str) -> ObjectType:
|
||||
mapping = {
|
||||
"slice": ObjectType.chart,
|
||||
"dashboard": ObjectType.dashboard,
|
||||
"query": ObjectType.query,
|
||||
"dataset": ObjectType.dataset,
|
||||
"slice": ObjectType.CHART,
|
||||
"dashboard": ObjectType.DASHBOARD,
|
||||
"query": ObjectType.QUERY,
|
||||
"dataset": ObjectType.DATASET,
|
||||
}
|
||||
try:
|
||||
return mapping[class_name.lower()]
|
||||
|
@ -176,7 +176,7 @@ class ObjectUpdater:
|
|||
tag_ids = set()
|
||||
for owner_id in cls.get_owners_ids(target):
|
||||
name = f"owner:{owner_id}"
|
||||
tag = get_tag(name, session, TagType.owner)
|
||||
tag = get_tag(name, session, TagType.OWNER)
|
||||
tag_ids.add(tag.id)
|
||||
return tag_ids
|
||||
|
||||
|
@ -188,7 +188,7 @@ class ObjectUpdater:
|
|||
) -> None:
|
||||
for owner_id in cls.get_owners_ids(target):
|
||||
name: str = f"owner:{owner_id}"
|
||||
tag = get_tag(name, session, TagType.owner)
|
||||
tag = get_tag(name, session, TagType.OWNER)
|
||||
cls.add_tag_object_if_not_tagged(
|
||||
session, tag_id=tag.id, object_id=target.id, object_type=cls.object_type
|
||||
)
|
||||
|
@ -228,7 +228,7 @@ class ObjectUpdater:
|
|||
cls._add_owners(session, target)
|
||||
|
||||
# add `type:` tags
|
||||
tag = get_tag(f"type:{cls.object_type}", session, TagType.type)
|
||||
tag = get_tag(f"type:{cls.object_type}", session, TagType.TYPE)
|
||||
cls.add_tag_object_if_not_tagged(
|
||||
session, tag_id=tag.id, object_id=target.id, object_type=cls.object_type
|
||||
)
|
||||
|
@ -249,7 +249,7 @@ class ObjectUpdater:
|
|||
.filter(
|
||||
TaggedObject.object_type == cls.object_type,
|
||||
TaggedObject.object_id == target.id,
|
||||
Tag.type == TagType.owner,
|
||||
Tag.type == TagType.OWNER,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
@ -329,7 +329,7 @@ class FavStarUpdater:
|
|||
) -> None:
|
||||
with Session(bind=connection) as session: # pylint: disable=disallowed-name
|
||||
name = f"favorited_by:{target.user_id}"
|
||||
tag = get_tag(name, session, TagType.favorited_by)
|
||||
tag = get_tag(name, session, TagType.FAVORITED_BY)
|
||||
tagged_object = TaggedObject(
|
||||
tag_id=tag.id,
|
||||
object_id=target.obj_id,
|
||||
|
@ -349,7 +349,7 @@ class FavStarUpdater:
|
|||
.join(Tag)
|
||||
.filter(
|
||||
TaggedObject.object_id == target.obj_id,
|
||||
Tag.type == TagType.favorited_by,
|
||||
Tag.type == TagType.FAVORITED_BY,
|
||||
Tag.name == name,
|
||||
)
|
||||
)
|
||||
|
|
|
@ -99,7 +99,7 @@ class TestCacheWarmUp(SupersetTestCase):
|
|||
"load_unicode_dashboard_with_slice", "load_birth_names_dashboard_with_slices"
|
||||
)
|
||||
def test_dashboard_tags_strategy(self):
|
||||
tag1 = get_tag("tag1", db.session, TagType.custom)
|
||||
tag1 = get_tag("tag1", db.session, TagType.CUSTOM)
|
||||
# delete first to make test idempotent
|
||||
self.reset_tag(tag1)
|
||||
|
||||
|
@ -109,11 +109,11 @@ class TestCacheWarmUp(SupersetTestCase):
|
|||
self.assertEqual(result, expected)
|
||||
|
||||
# tag dashboard 'births' with `tag1`
|
||||
tag1 = get_tag("tag1", db.session, TagType.custom)
|
||||
tag1 = get_tag("tag1", db.session, TagType.CUSTOM)
|
||||
dash = self.get_dash_by_slug("births")
|
||||
tag1_urls = [{"chart_id": chart.id} for chart in dash.slices]
|
||||
tagged_object = TaggedObject(
|
||||
tag_id=tag1.id, object_id=dash.id, object_type=ObjectType.dashboard
|
||||
tag_id=tag1.id, object_id=dash.id, object_type=ObjectType.DASHBOARD
|
||||
)
|
||||
db.session.add(tagged_object)
|
||||
db.session.commit()
|
||||
|
@ -121,7 +121,7 @@ class TestCacheWarmUp(SupersetTestCase):
|
|||
self.assertCountEqual(strategy.get_payloads(), tag1_urls)
|
||||
|
||||
strategy = DashboardTagsStrategy(["tag2"])
|
||||
tag2 = get_tag("tag2", db.session, TagType.custom)
|
||||
tag2 = get_tag("tag2", db.session, TagType.CUSTOM)
|
||||
self.reset_tag(tag2)
|
||||
|
||||
result = strategy.get_payloads()
|
||||
|
@ -134,7 +134,7 @@ class TestCacheWarmUp(SupersetTestCase):
|
|||
tag2_urls = [{"chart_id": chart.id}]
|
||||
object_id = chart.id
|
||||
tagged_object = TaggedObject(
|
||||
tag_id=tag2.id, object_id=object_id, object_type=ObjectType.chart
|
||||
tag_id=tag2.id, object_id=object_id, object_type=ObjectType.CHART
|
||||
)
|
||||
db.session.add(tagged_object)
|
||||
db.session.commit()
|
||||
|
|
|
@ -72,7 +72,7 @@ class TestTagging(SupersetTestCase):
|
|||
# Test to make sure that a dataset tag was added to the tagged_object table
|
||||
tags = self.query_tagged_object_table()
|
||||
self.assertEqual(1, len(tags))
|
||||
self.assertEqual("ObjectType.dataset", str(tags[0].object_type))
|
||||
self.assertEqual("ObjectType.DATASET", str(tags[0].object_type))
|
||||
self.assertEqual(test_dataset.id, tags[0].object_id)
|
||||
|
||||
# Cleanup the db
|
||||
|
@ -110,7 +110,7 @@ class TestTagging(SupersetTestCase):
|
|||
# Test to make sure that a chart tag was added to the tagged_object table
|
||||
tags = self.query_tagged_object_table()
|
||||
self.assertEqual(1, len(tags))
|
||||
self.assertEqual("ObjectType.chart", str(tags[0].object_type))
|
||||
self.assertEqual("ObjectType.CHART", str(tags[0].object_type))
|
||||
self.assertEqual(test_chart.id, tags[0].object_id)
|
||||
|
||||
# Cleanup the db
|
||||
|
@ -146,7 +146,7 @@ class TestTagging(SupersetTestCase):
|
|||
# Test to make sure that a dashboard tag was added to the tagged_object table
|
||||
tags = self.query_tagged_object_table()
|
||||
self.assertEqual(1, len(tags))
|
||||
self.assertEqual("ObjectType.dashboard", str(tags[0].object_type))
|
||||
self.assertEqual("ObjectType.DASHBOARD", str(tags[0].object_type))
|
||||
self.assertEqual(test_dashboard.id, tags[0].object_id)
|
||||
|
||||
# Cleanup the db
|
||||
|
@ -180,14 +180,14 @@ class TestTagging(SupersetTestCase):
|
|||
|
||||
self.assertEqual(2, len(tags))
|
||||
|
||||
self.assertEqual("ObjectType.query", str(tags[0].object_type))
|
||||
self.assertEqual("ObjectType.QUERY", str(tags[0].object_type))
|
||||
self.assertEqual("owner:None", str(tags[0].tag.name))
|
||||
self.assertEqual("TagType.owner", str(tags[0].tag.type))
|
||||
self.assertEqual("TagType.OWNER", str(tags[0].tag.type))
|
||||
self.assertEqual(test_saved_query.id, tags[0].object_id)
|
||||
|
||||
self.assertEqual("ObjectType.query", str(tags[1].object_type))
|
||||
self.assertEqual("ObjectType.QUERY", str(tags[1].object_type))
|
||||
self.assertEqual("type:query", str(tags[1].tag.name))
|
||||
self.assertEqual("TagType.type", str(tags[1].tag.type))
|
||||
self.assertEqual("TagType.TYPE", str(tags[1].tag.type))
|
||||
self.assertEqual(test_saved_query.id, tags[1].object_id)
|
||||
|
||||
# Cleanup the db
|
||||
|
@ -219,7 +219,7 @@ class TestTagging(SupersetTestCase):
|
|||
# Test to make sure that a favorited object tag was added to the tagged_object table
|
||||
tags = self.query_tagged_object_table()
|
||||
self.assertEqual(1, len(tags))
|
||||
self.assertEqual("ObjectType.chart", str(tags[0].object_type))
|
||||
self.assertEqual("ObjectType.CHART", str(tags[0].object_type))
|
||||
self.assertEqual(test_saved_query.obj_id, tags[0].object_id)
|
||||
|
||||
# Cleanup the db
|
||||
|
|
|
@ -142,7 +142,7 @@ class TestTagApi(SupersetTestCase):
|
|||
"created_by": None,
|
||||
"id": tag.id,
|
||||
"name": "test get tag",
|
||||
"type": TagType.custom.value,
|
||||
"type": TagType.CUSTOM.value,
|
||||
}
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
for key, value in expected_result.items():
|
||||
|
@ -243,7 +243,7 @@ class TestTagApi(SupersetTestCase):
|
|||
.first()
|
||||
)
|
||||
dashboard_id = dashboard.id
|
||||
dashboard_type = ObjectType.dashboard.value
|
||||
dashboard_type = ObjectType.DASHBOARD.value
|
||||
uri = f"api/v1/tag/{dashboard_type}/{dashboard_id}/"
|
||||
example_tag_names = ["example_tag_1", "example_tag_2"]
|
||||
data = {"properties": {"tags": example_tag_names}}
|
||||
|
@ -258,7 +258,7 @@ class TestTagApi(SupersetTestCase):
|
|||
tagged_objects = db.session.query(TaggedObject).filter(
|
||||
TaggedObject.tag_id.in_(tag_ids),
|
||||
TaggedObject.object_id == dashboard_id,
|
||||
TaggedObject.object_type == ObjectType.dashboard,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD,
|
||||
)
|
||||
assert tagged_objects.count() == 2
|
||||
# clean up tags and tagged objects
|
||||
|
@ -276,7 +276,7 @@ class TestTagApi(SupersetTestCase):
|
|||
def test_delete_tagged_objects(self):
|
||||
self.login(ADMIN_USERNAME)
|
||||
dashboard_id = 1
|
||||
dashboard_type = ObjectType.dashboard
|
||||
dashboard_type = ObjectType.DASHBOARD
|
||||
tag_names = ["example_tag_1", "example_tag_2"]
|
||||
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
|
||||
assert tags.count() == 2
|
||||
|
@ -346,7 +346,7 @@ class TestTagApi(SupersetTestCase):
|
|||
.first()
|
||||
)
|
||||
dashboard_id = dashboard.id
|
||||
dashboard_type = ObjectType.dashboard
|
||||
dashboard_type = ObjectType.DASHBOARD
|
||||
tag_names = ["example_tag_1", "example_tag_2"]
|
||||
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
|
||||
for tag in tags:
|
||||
|
@ -382,7 +382,7 @@ class TestTagApi(SupersetTestCase):
|
|||
.first()
|
||||
)
|
||||
dashboard_id = dashboard.id
|
||||
dashboard_type = ObjectType.dashboard
|
||||
dashboard_type = ObjectType.DASHBOARD
|
||||
tag_names = ["example_tag_1", "example_tag_2"]
|
||||
tags = db.session.query(Tag).filter(Tag.name.in_(tag_names))
|
||||
for tag in tags:
|
||||
|
@ -531,7 +531,7 @@ class TestTagApi(SupersetTestCase):
|
|||
self.get_user(username="admin").get_id() # noqa: F841
|
||||
tag = (
|
||||
db.session.query(Tag)
|
||||
.filter(Tag.name == "my_tag", Tag.type == TagType.custom)
|
||||
.filter(Tag.name == "my_tag", Tag.type == TagType.CUSTOM)
|
||||
.one_or_none()
|
||||
)
|
||||
assert tag is not None
|
||||
|
@ -630,8 +630,8 @@ class TestTagApi(SupersetTestCase):
|
|||
.join(Tag)
|
||||
.filter(
|
||||
TaggedObject.object_id == dashboard.id,
|
||||
TaggedObject.object_type == ObjectType.dashboard,
|
||||
Tag.type == TagType.custom,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD,
|
||||
Tag.type == TagType.CUSTOM,
|
||||
)
|
||||
)
|
||||
assert tagged_objects.count() == 2
|
||||
|
@ -641,8 +641,8 @@ class TestTagApi(SupersetTestCase):
|
|||
.join(Tag)
|
||||
.filter(
|
||||
TaggedObject.object_id == chart.id,
|
||||
TaggedObject.object_type == ObjectType.chart,
|
||||
Tag.type == TagType.custom,
|
||||
TaggedObject.object_type == ObjectType.CHART,
|
||||
Tag.type == TagType.CUSTOM,
|
||||
)
|
||||
)
|
||||
assert tagged_objects.count() == 2
|
||||
|
|
|
@ -65,9 +65,9 @@ class TestCreateCustomTagCommand(SupersetTestCase):
|
|||
example_dashboard = (
|
||||
db.session.query(Dashboard).filter_by(slug="world_health").one()
|
||||
)
|
||||
example_tags = {"create custom tag example 1", "create custom tag example 2"}
|
||||
example_tags = ["create custom tag example 1", "create custom tag example 2"]
|
||||
command = CreateCustomTagCommand(
|
||||
ObjectType.dashboard.value, example_dashboard.id, example_tags
|
||||
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
|
||||
)
|
||||
command.run()
|
||||
|
||||
|
@ -76,7 +76,7 @@ class TestCreateCustomTagCommand(SupersetTestCase):
|
|||
.join(TaggedObject)
|
||||
.filter(
|
||||
TaggedObject.object_id == example_dashboard.id,
|
||||
Tag.type == TagType.custom,
|
||||
Tag.type == TagType.CUSTOM,
|
||||
)
|
||||
.all()
|
||||
)
|
||||
|
@ -101,9 +101,9 @@ class TestDeleteTagsCommand(SupersetTestCase):
|
|||
.filter_by(dashboard_title="World Bank's Data")
|
||||
.one()
|
||||
)
|
||||
example_tags = {"create custom tag example 1", "create custom tag example 2"}
|
||||
example_tags = ["create custom tag example 1", "create custom tag example 2"]
|
||||
command = CreateCustomTagCommand(
|
||||
ObjectType.dashboard.value, example_dashboard.id, example_tags
|
||||
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
|
||||
)
|
||||
command.run()
|
||||
|
||||
|
@ -112,7 +112,7 @@ class TestDeleteTagsCommand(SupersetTestCase):
|
|||
.join(TaggedObject)
|
||||
.filter(
|
||||
TaggedObject.object_id == example_dashboard.id,
|
||||
Tag.type == TagType.custom,
|
||||
Tag.type == TagType.CUSTOM,
|
||||
)
|
||||
.order_by(Tag.name)
|
||||
.all()
|
||||
|
@ -134,9 +134,9 @@ class TestDeleteTaggedObjectCommand(SupersetTestCase):
|
|||
example_dashboard = (
|
||||
db.session.query(Dashboard).filter_by(slug="world_health").one()
|
||||
)
|
||||
example_tags = {"create custom tag example 1", "create custom tag example 2"}
|
||||
example_tags = ["create custom tag example 1", "create custom tag example 2"]
|
||||
command = CreateCustomTagCommand(
|
||||
ObjectType.dashboard.value, example_dashboard.id, example_tags
|
||||
ObjectType.DASHBOARD.value, example_dashboard.id, example_tags
|
||||
)
|
||||
command.run()
|
||||
|
||||
|
@ -145,14 +145,14 @@ class TestDeleteTaggedObjectCommand(SupersetTestCase):
|
|||
.join(Tag)
|
||||
.filter(
|
||||
TaggedObject.object_id == example_dashboard.id,
|
||||
TaggedObject.object_type == ObjectType.dashboard.name,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD.name,
|
||||
Tag.name.in_(example_tags),
|
||||
)
|
||||
)
|
||||
assert tagged_objects.count() == 2
|
||||
# delete one of the tagged objects
|
||||
command = DeleteTaggedObjectCommand(
|
||||
object_type=ObjectType.dashboard.value,
|
||||
object_type=ObjectType.DASHBOARD.value,
|
||||
object_id=example_dashboard.id,
|
||||
tag=list(example_tags)[0],
|
||||
)
|
||||
|
@ -162,7 +162,7 @@ class TestDeleteTaggedObjectCommand(SupersetTestCase):
|
|||
.join(Tag)
|
||||
.filter(
|
||||
TaggedObject.object_id == example_dashboard.id,
|
||||
TaggedObject.object_type == ObjectType.dashboard.name,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD.name,
|
||||
Tag.name.in_(example_tags),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -113,7 +113,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
tagged_objects.append(
|
||||
self.insert_tagged_object(
|
||||
object_id=dashboard_id,
|
||||
object_type=ObjectType.dashboard,
|
||||
object_type=ObjectType.DASHBOARD,
|
||||
tag_id=tag.id,
|
||||
)
|
||||
)
|
||||
|
@ -126,21 +126,21 @@ class TestTagsDAO(SupersetTestCase):
|
|||
def test_create_tagged_objects(self):
|
||||
# test that a tag can be added if it has ':' in it
|
||||
TagDAO.create_custom_tagged_objects(
|
||||
object_type=ObjectType.dashboard.name,
|
||||
object_type=ObjectType.DASHBOARD,
|
||||
object_id=1,
|
||||
tag_names=["valid:example tag 1"],
|
||||
)
|
||||
|
||||
# test that a tag can be added if it has ',' in it
|
||||
TagDAO.create_custom_tagged_objects(
|
||||
object_type=ObjectType.dashboard.name,
|
||||
object_type=ObjectType.DASHBOARD,
|
||||
object_id=1,
|
||||
tag_names=["example,tag,1"],
|
||||
)
|
||||
|
||||
# test that a tag can be added if it has a valid name
|
||||
TagDAO.create_custom_tagged_objects(
|
||||
object_type=ObjectType.dashboard.name,
|
||||
object_type=ObjectType.DASHBOARD,
|
||||
object_id=1,
|
||||
tag_names=["example tag 1"],
|
||||
)
|
||||
|
@ -161,7 +161,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
dashboard_id = dashboard.id
|
||||
tag = db.session.query(Tag).filter_by(name="example_tag_1").one()
|
||||
self.insert_tagged_object(
|
||||
object_id=dashboard_id, object_type=ObjectType.dashboard, tag_id=tag.id
|
||||
object_id=dashboard_id, object_type=ObjectType.DASHBOARD, tag_id=tag.id
|
||||
)
|
||||
# get objects
|
||||
tagged_objects = TagDAO.get_tagged_objects_for_tags(
|
||||
|
@ -185,7 +185,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
TaggedObject,
|
||||
and_(
|
||||
TaggedObject.object_id == Slice.id,
|
||||
TaggedObject.object_type == ObjectType.chart,
|
||||
TaggedObject.object_type == ObjectType.CHART,
|
||||
),
|
||||
)
|
||||
.distinct(Slice.id)
|
||||
|
@ -197,7 +197,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
TaggedObject,
|
||||
and_(
|
||||
TaggedObject.object_id == Dashboard.id,
|
||||
TaggedObject.object_type == ObjectType.dashboard,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD,
|
||||
),
|
||||
)
|
||||
.distinct(Dashboard.id)
|
||||
|
@ -229,7 +229,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
tag_2 = db.session.query(Tag).filter_by(name="example_tag_2").one()
|
||||
tag_ids = [tag_1.id, tag_2.id]
|
||||
self.insert_tagged_object(
|
||||
object_id=dashboard_id, object_type=ObjectType.dashboard, tag_id=tag_1.id
|
||||
object_id=dashboard_id, object_type=ObjectType.DASHBOARD, tag_id=tag_1.id
|
||||
)
|
||||
# get objects
|
||||
tagged_objects = TagDAO.get_tagged_objects_by_tag_id(tag_ids)
|
||||
|
@ -252,7 +252,7 @@ class TestTagsDAO(SupersetTestCase):
|
|||
def test_find_tagged_object(self):
|
||||
tag = db.session.query(Tag).filter(Tag.name == "example_tag_1").first()
|
||||
tagged_object = TagDAO.find_tagged_object(
|
||||
object_id=1, object_type=ObjectType.dashboard.name, tag_id=tag.id
|
||||
object_id=1, object_type=ObjectType.DASHBOARD, tag_id=tag.id
|
||||
)
|
||||
assert tagged_object is not None
|
||||
|
||||
|
@ -308,20 +308,20 @@ class TestTagsDAO(SupersetTestCase):
|
|||
.filter(
|
||||
TaggedObject.tag_id == tag.id,
|
||||
TaggedObject.object_id == 1,
|
||||
TaggedObject.object_type == ObjectType.dashboard.name,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD.name,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
assert tagged_object is not None
|
||||
TagDAO.delete_tagged_object(
|
||||
object_type=ObjectType.dashboard.name, object_id=1, tag_name=tag.name
|
||||
object_type=ObjectType.DASHBOARD, object_id=1, tag_name=tag.name
|
||||
)
|
||||
tagged_object = (
|
||||
db.session.query(TaggedObject)
|
||||
.filter(
|
||||
TaggedObject.tag_id == tag.id,
|
||||
TaggedObject.object_id == 1,
|
||||
TaggedObject.object_type == ObjectType.dashboard.name,
|
||||
TaggedObject.object_type == ObjectType.DASHBOARD.name,
|
||||
)
|
||||
.first()
|
||||
)
|
||||
|
|
|
@ -156,9 +156,9 @@ def test_create_tag_relationship(mocker):
|
|||
|
||||
# Define a list of objects to tag
|
||||
objects_to_tag = [
|
||||
(ObjectType.query, 1),
|
||||
(ObjectType.chart, 2),
|
||||
(ObjectType.dashboard, 3),
|
||||
(ObjectType.QUERY, 1),
|
||||
(ObjectType.CHART, 2),
|
||||
(ObjectType.DASHBOARD, 3),
|
||||
]
|
||||
|
||||
# Call the function
|
||||
|
|
|
@ -86,9 +86,9 @@ def test_create_command_success(session_with_data: Session, mocker: MockFixture)
|
|||
mocker.patch("superset.daos.query.SavedQueryDAO.find_by_id", return_value=query)
|
||||
|
||||
objects_to_tag = [
|
||||
(ObjectType.query, query.id),
|
||||
(ObjectType.chart, chart.id),
|
||||
(ObjectType.dashboard, dashboard.id),
|
||||
(ObjectType.QUERY, query.id),
|
||||
(ObjectType.CHART, chart.id),
|
||||
(ObjectType.DASHBOARD, dashboard.id),
|
||||
]
|
||||
|
||||
CreateCustomTagWithRelationshipsCommand(
|
||||
|
@ -127,9 +127,9 @@ def test_create_command_success_clear(session_with_data: Session, mocker: MockFi
|
|||
mocker.patch("superset.daos.query.SavedQueryDAO.find_by_id", return_value=query)
|
||||
|
||||
objects_to_tag = [
|
||||
(ObjectType.query, query.id),
|
||||
(ObjectType.chart, chart.id),
|
||||
(ObjectType.dashboard, dashboard.id),
|
||||
(ObjectType.QUERY, query.id),
|
||||
(ObjectType.CHART, chart.id),
|
||||
(ObjectType.DASHBOARD, dashboard.id),
|
||||
]
|
||||
|
||||
CreateCustomTagWithRelationshipsCommand(
|
||||
|
|
|
@ -91,7 +91,7 @@ def test_update_command_success(session_with_data: Session, mocker: MockFixture)
|
|||
)
|
||||
|
||||
objects_to_tag = [
|
||||
(ObjectType.dashboard, dashboard.id),
|
||||
(ObjectType.DASHBOARD, dashboard.id),
|
||||
]
|
||||
|
||||
tag_to_update = TagDAO.find_by_name("test_name")
|
||||
|
@ -132,7 +132,7 @@ def test_update_command_success_duplicates(
|
|||
)
|
||||
|
||||
objects_to_tag = [
|
||||
(ObjectType.dashboard, dashboard.id),
|
||||
(ObjectType.DASHBOARD, dashboard.id),
|
||||
]
|
||||
|
||||
CreateCustomTagWithRelationshipsCommand(
|
||||
|
@ -142,7 +142,7 @@ def test_update_command_success_duplicates(
|
|||
tag_to_update = TagDAO.find_by_name("test_tag")
|
||||
|
||||
objects_to_tag = [
|
||||
(ObjectType.chart, chart.id),
|
||||
(ObjectType.CHART, chart.id),
|
||||
]
|
||||
changed_model = UpdateTagCommand(
|
||||
tag_to_update.id,
|
||||
|
@ -174,7 +174,7 @@ def test_update_command_failed_validation(
|
|||
dashboard = db.session.query(Dashboard).first()
|
||||
chart = db.session.query(Slice).first()
|
||||
objects_to_tag = [
|
||||
(ObjectType.chart, chart.id),
|
||||
(ObjectType.CHART, chart.id),
|
||||
]
|
||||
|
||||
mocker.patch(
|
||||
|
|
Loading…
Reference in New Issue