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 a62349b
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 62 deletions.
7 changes: 4 additions & 3 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)

Check warning on line 66 in superset/commands/chart/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/chart/update.py#L66

Added line #L66 was not covered by tests

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

Check warning on line 82 in superset/commands/chart/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/chart/update.py#L82

Added line #L82 was not covered by tests
if datasource_id is not None:
datasource_type = self._properties.get("datasource_type", "")
if not datasource_type:
Expand Down Expand Up @@ -106,12 +107,12 @@ 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)

Check warning on line 110 in superset/commands/chart/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/chart/update.py#L110

Added line #L110 was not covered by tests
except ValidationError as ex:
exceptions.append(ex)

# Validate/Populate datasource
if datasource_id is not None:
if datasource_id is not None and datasource_type is not None:

Check warning on line 115 in superset/commands/chart/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/chart/update.py#L115

Added line #L115 was not covered by tests
try:
datasource = get_datasource_by_id(datasource_id, datasource_type)
self._properties["datasource_name"] = datasource.name
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)

Check warning on line 63 in superset/commands/dashboard/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/dashboard/update.py#L63

Added line #L63 was not covered by tests

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)

Check warning on line 106 in superset/commands/dashboard/update.py

View check run for this annotation

Codecov / codecov/patch

superset/commands/dashboard/update.py#L106

Added line #L106 was not covered by tests
except ValidationError as ex:
exceptions.append(ex)

Expand Down
8 changes: 4 additions & 4 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 All @@ -140,7 +140,7 @@ def validate_tags(
or security_manager.can_access("can_tag", object_type.name.capitalize())
):
validation_error = (
f"You do not have permission to manage tags on {object_type.name}s"
f"You do not have permission to manage tags on {object_type.name.lower()}s"
)
raise TagForbiddenError(validation_error)

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
28 changes: 14 additions & 14 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 Expand Up @@ -2136,7 +2136,7 @@ def test_update_chart_add_tags_can_write_on_tag(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand All @@ -2146,7 +2146,7 @@ def test_update_chart_add_tags_can_write_on_tag(self):
model = db.session.query(Slice).get(chart.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == new_tags

@pytest.mark.usefixtures("create_chart_with_tag")
Expand All @@ -2162,7 +2162,7 @@ def test_update_chart_remove_tags_can_write_on_tag(self):
)

# get existing tag and add a new one
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.CUSTOM]
new_tags.pop()

update_payload = {"tags": new_tags}
Expand All @@ -2173,7 +2173,7 @@ def test_update_chart_remove_tags_can_write_on_tag(self):
model = db.session.query(Slice).get(chart.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == new_tags

@pytest.mark.usefixtures("create_chart_with_tag")
Expand All @@ -2195,7 +2195,7 @@ def test_update_chart_add_tags_can_tag_on_chart(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand All @@ -2205,7 +2205,7 @@ def test_update_chart_add_tags_can_tag_on_chart(self):
model = db.session.query(Slice).get(chart.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == new_tags

security_manager.add_permission_role(alpha_role, write_tags_perm)
Expand Down Expand Up @@ -2235,7 +2235,7 @@ def test_update_chart_remove_tags_can_tag_on_chart(self):
model = db.session.query(Slice).get(chart.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == []

security_manager.add_permission_role(alpha_role, write_tags_perm)
Expand All @@ -2260,7 +2260,7 @@ def test_update_chart_add_tags_missing_permission(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in chart.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand Down Expand Up @@ -2321,7 +2321,7 @@ def test_update_chart_no_tag_changes(self):
chart = (
db.session.query(Slice).filter(Slice.slice_name == "chart with tag").first()
)
existing_tags = [tag.id for tag in chart.tags if tag.type == TagType.custom]
existing_tags = [tag.id for tag in chart.tags if tag.type == TagType.CUSTOM]
update_payload = {"tags": existing_tags}

uri = f"api/v1/chart/{chart.id}"
Expand Down
28 changes: 14 additions & 14 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 Expand Up @@ -2804,7 +2804,7 @@ def test_update_dashboard_add_tags_can_write_on_tag(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand All @@ -2814,7 +2814,7 @@ def test_update_dashboard_add_tags_can_write_on_tag(self):
model = db.session.query(Dashboard).get(dashboard.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert sorted(tag_list) == sorted(new_tags)

@pytest.mark.usefixtures("create_dashboard_with_tag")
Expand All @@ -2832,7 +2832,7 @@ def test_update_dashboard_remove_tags_can_write_on_tag(self):
)

# get existing tag and add a new one
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.CUSTOM]
new_tags.pop()

update_payload = {"tags": new_tags}
Expand All @@ -2843,7 +2843,7 @@ def test_update_dashboard_remove_tags_can_write_on_tag(self):
model = db.session.query(Dashboard).get(dashboard.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == new_tags

@pytest.mark.usefixtures("create_dashboard_with_tag")
Expand All @@ -2866,7 +2866,7 @@ def test_update_dashboard_add_tags_can_tag_on_dashboard(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand All @@ -2876,7 +2876,7 @@ def test_update_dashboard_add_tags_can_tag_on_dashboard(self):
model = db.session.query(Dashboard).get(dashboard.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert sorted(tag_list) == sorted(new_tags)

security_manager.add_permission_role(gamma_role, write_tags_perm)
Expand Down Expand Up @@ -2907,7 +2907,7 @@ def test_update_dashboard_remove_tags_can_tag_on_dashboard(self):
model = db.session.query(Dashboard).get(dashboard.id)

# Clean up system tags
tag_list = [tag.id for tag in model.tags if tag.type == TagType.custom]
tag_list = [tag.id for tag in model.tags if tag.type == TagType.CUSTOM]
assert tag_list == []

security_manager.add_permission_role(gamma_role, write_tags_perm)
Expand Down Expand Up @@ -2935,7 +2935,7 @@ def test_update_dashboard_add_tags_missing_permission(self):
new_tag = db.session.query(Tag).filter(Tag.name == "second_tag").one()

# get existing tag and add a new one
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.custom]
new_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.CUSTOM]
new_tags.append(new_tag.id)
update_payload = {"tags": new_tags}

Expand Down Expand Up @@ -3004,7 +3004,7 @@ def test_update_dashboard_no_tag_changes(self):
.filter(Dashboard.dashboard_title == "dash with tag")
.first()
)
existing_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.custom]
existing_tags = [tag.id for tag in dashboard.tags if tag.type == TagType.CUSTOM]
update_payload = {"tags": existing_tags}

uri = f"api/v1/dashboard/{dashboard.id}"
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
Loading

0 comments on commit a62349b

Please sign in to comment.