Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Dec 11, 2024
1 parent baa2724 commit a50fdf6
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 28 deletions.
5 changes: 3 additions & 2 deletions superset/commands/chart/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def run(self) -> Model:

# Update tags
if (tags := self._properties.pop("tags", None)) is not None:
update_tags(ObjectType.chart, self._model.id, self._model.tags, tags)
update_tags(ObjectType.CHART, self._model.id, self._model.tags, tags)

if self._properties.get("query_context_generation") is None:
self._properties["last_saved_at"] = datetime.now()
Expand All @@ -79,6 +79,7 @@ def validate(self) -> None:

# Validate if datasource_id is provided datasource_type is required
datasource_id = self._properties.get("datasource_id")
datasource_type: str | None = None
if datasource_id is not None:
datasource_type = self._properties.get("datasource_type", "")
if not datasource_type:
Expand Down Expand Up @@ -106,7 +107,7 @@ def validate(self) -> None:

# validate tags
try:
validate_tags(ObjectType.chart, self._model.tags, tag_ids)
validate_tags(ObjectType.CHART, self._model.tags, tag_ids)
except ValidationError as ex:
exceptions.append(ex)

Expand Down
4 changes: 2 additions & 2 deletions superset/commands/dashboard/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def run(self) -> Model:

# Update tags
if (tags := self._properties.pop("tags", None)) is not None:
update_tags(ObjectType.dashboard, self._model.id, self._model.tags, tags)
update_tags(ObjectType.DASHBOARD, self._model.id, self._model.tags, tags)

dashboard = DashboardDAO.update(self._model, self._properties)
if self._properties.get("json_metadata"):
Expand Down Expand Up @@ -103,7 +103,7 @@ def validate(self) -> None:

# validate tags
try:
validate_tags(ObjectType.dashboard, self._model.tags, tag_ids)
validate_tags(ObjectType.DASHBOARD, self._model.tags, tag_ids)
except ValidationError as ex:
exceptions.append(ex)

Expand Down
6 changes: 3 additions & 3 deletions superset/commands/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def validate_tags(
return

# No changes in the list
current_custom_tags = [tag.id for tag in current_tags if tag.type == TagType.custom]
current_custom_tags = [tag.id for tag in current_tags if tag.type == TagType.CUSTOM]
if Counter(current_custom_tags) == Counter(new_tag_ids):
return

Expand Down Expand Up @@ -169,9 +169,9 @@ def update_tags(
:param new_tag_ids: list of tags specified in the update payload
"""

current_custom_tags = [tag for tag in current_tags if tag.type == TagType.custom]
current_custom_tags = [tag for tag in current_tags if tag.type == TagType.CUSTOM]
current_custom_tag_ids = [
tag.id for tag in current_tags if tag.type == TagType.custom
tag.id for tag in current_tags if tag.type == TagType.CUSTOM
]

tags_to_delete = [tag for tag in current_custom_tags if tag.id not in new_tag_ids]
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/charts/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def create_chart_with_tag(self, create_custom_tags): # noqa: F811
tag = db.session.query(Tag).filter(Tag.name == "first_tag").first()
tag_association = TaggedObject(
object_id=chart.id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tag,
)

Expand Down Expand Up @@ -263,22 +263,22 @@ def create_charts_some_with_tags(self, create_custom_tags): # noqa: F811
tag_associations = [
TaggedObject(
object_id=charts[0].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=charts[1].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
TaggedObject(
object_id=charts[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=charts[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
]
Expand Down
10 changes: 5 additions & 5 deletions tests/integration_tests/dashboards/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def create_dashboard_with_tag(self, create_custom_tags): # noqa: F811
tag = db.session.query(Tag).filter(Tag.name == "first_tag").first()
tag_association = TaggedObject(
object_id=dashboard.id,
object_type=ObjectType.dashboard,
object_type=ObjectType.DASHBOARD,
tag=tag,
)

Expand Down Expand Up @@ -245,22 +245,22 @@ def create_dashboards_some_with_tags(self, create_custom_tags): # noqa: F811
tag_associations = [
TaggedObject(
object_id=dashboards[0].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=dashboards[1].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
TaggedObject(
object_id=dashboards[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=dashboards[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
]
Expand Down
8 changes: 4 additions & 4 deletions tests/integration_tests/queries/saved_queries/api_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,22 +163,22 @@ def create_saved_queries_some_with_tags(self, create_custom_tags): # noqa: F811
tag_associations = [
TaggedObject(
object_id=queries[0].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=queries[1].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
TaggedObject(
object_id=queries[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["first_tag"],
),
TaggedObject(
object_id=queries[2].id,
object_type=ObjectType.chart,
object_type=ObjectType.CHART,
tag=tags["second_tag"],
),
]
Expand Down
14 changes: 7 additions & 7 deletions tests/unit_tests/commands/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,37 +32,37 @@
)
from superset.tags.models import ObjectType

OBJECT_TYPES = {ObjectType.chart, ObjectType.chart}
OBJECT_TYPES = {ObjectType.CHART, ObjectType.CHART}
MOCK_TAGS = [
Tag(
id=1,
name="first",
type=TagType.custom,
type=TagType.CUSTOM,
),
Tag(
id=2,
name="second",
type=TagType.custom,
type=TagType.CUSTOM,
),
Tag(
id=3,
name="third",
type=TagType.custom,
type=TagType.CUSTOM,
),
Tag(
id=4,
name="type:dashboard",
type=TagType.type,
type=TagType.TYPE,
),
Tag(
id=4,
name="owner:1",
type=TagType.owner,
type=TagType.OWNER,
),
Tag(
id=4,
name="avorited_by:2",
type=TagType.favorited_by,
type=TagType.FAVORITED_BY,
),
]

Expand Down

0 comments on commit a50fdf6

Please sign in to comment.