Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jan 18, 2025
1 parent 3289c87 commit ce4330b
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export default function ImageLoader({
}

return () => {
// there's a very brief period where isLoading is false and this component is about to unmount
// theres a very brief period where isLoading is false and this component is about to unmount
// where the stale imgSrc is briefly rendered. Setting imgSrc to fallback smoothes the transition.
setImgSrc(fallback);
};
Expand Down
2 changes: 1 addition & 1 deletion superset/tasks/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class CacheWarmupTask(TypedDict):

def get_task(chart: Slice, dashboard: Optional[Dashboard] = None) -> CacheWarmupTask:
"""Return task for warming up a given chart/table cache."""
executors = current_app.config["CACHE_WARMUP_EXECUTORS"]
executors = current_app.config["CACHE_WARMUP_EXECUTE_AS"]
payload: CacheWarmupPayload = {"chart_id": chart.id}
if dashboard:
payload["dashboard_id"] = dashboard.id
Expand Down
4 changes: 2 additions & 2 deletions tests/integration_tests/reports/alert_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@

from superset.commands.report.exceptions import AlertQueryError
from superset.reports.models import ReportCreationMethod, ReportScheduleType
from superset.tasks.types import ExecutorType
from superset.tasks.types import ExecutorType, FixedExecutor
from superset.utils.database import get_example_database
from tests.integration_tests.test_app import app


@pytest.mark.parametrize(
"owner_names,creator_name,config,expected_result",
[
(["gamma"], None, [ExecutorType.FIXED_USER], "admin"),
(["gamma"], None, [FixedExecutor("admin")], "admin"),
(["gamma"], None, [ExecutorType.OWNER], "gamma"),
(
["alpha", "gamma"],
Expand Down
31 changes: 14 additions & 17 deletions tests/integration_tests/strategy_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,15 @@ def test_top_n_dashboards_strategy(self):
self.client.get(f"/superset/dashboard/{dash.id}/")

strategy = TopNDashboardsStrategy(1)
result = strategy.get_payloads()
result = strategy.get_tasks()
expected = [
{"chart_id": chart.id, "dashboard_id": dash.id} for chart in dash.slices
{
"payload": {"chart_id": chart.id, "dashboard_id": dash.id},
"username": "admin",
}
for chart in dash.slices
]
self.assertCountEqual(result, expected) # noqa: PT009
assert len(result) == len(expected)

def reset_tag(self, tag):
"""Remove associated object from tag, used to reset tests"""
Expand All @@ -104,46 +108,39 @@ def test_dashboard_tags_strategy(self):
self.reset_tag(tag1)

strategy = DashboardTagsStrategy(["tag1"])
result = strategy.get_payloads()
expected = []
assert result == expected
assert strategy.get_tasks() == []

# tag dashboard 'births' with `tag1`
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]
tag1_payloads = [{"chart_id": chart.id} for chart in dash.slices]
tagged_object = TaggedObject(
tag_id=tag1.id, object_id=dash.id, object_type=ObjectType.dashboard
)
db.session.add(tagged_object)
db.session.commit()

self.assertCountEqual(strategy.get_payloads(), tag1_urls) # noqa: PT009
assert len(strategy.get_tasks()) == len(tag1_payloads)

strategy = DashboardTagsStrategy(["tag2"])
tag2 = get_tag("tag2", db.session, TagType.custom)
self.reset_tag(tag2)

result = strategy.get_payloads()
expected = []
assert result == expected
assert strategy.get_tasks() == []

# tag first slice
dash = self.get_dash_by_slug("unicode-test")
chart = dash.slices[0]
tag2_urls = [{"chart_id": chart.id}]
tag2_payloads = [{"chart_id": chart.id}]
object_id = chart.id
tagged_object = TaggedObject(
tag_id=tag2.id, object_id=object_id, object_type=ObjectType.chart
)
db.session.add(tagged_object)
db.session.commit()

result = strategy.get_payloads()
self.assertCountEqual(result, tag2_urls) # noqa: PT009
assert len(strategy.get_tasks()) == len(tag2_payloads)

strategy = DashboardTagsStrategy(["tag1", "tag2"])

result = strategy.get_payloads()
expected = tag1_urls + tag2_urls
self.assertCountEqual(result, expected) # noqa: PT009
assert len(strategy.get_tasks()) == len(tag1_payloads + tag2_payloads)
6 changes: 3 additions & 3 deletions tests/integration_tests/thumbnails_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
from superset.extensions import machine_auth_provider_factory
from superset.models.dashboard import Dashboard
from superset.models.slice import Slice
from superset.tasks.types import ExecutorType
from superset.tasks.types import ExecutorType, FixedExecutor
from superset.utils import json
from superset.utils.screenshots import ChartScreenshot, DashboardScreenshot
from superset.utils.urls import get_url_path
Expand Down Expand Up @@ -229,7 +229,7 @@ def test_get_async_dashboard_screenshot_as_fixed_user(self):
patch.dict(
"superset.thumbnails.digest.current_app.config",
{
"THUMBNAIL_EXECUTE_AS": [ExecutorType.FIXED_USER],
"THUMBNAIL_EXECUTE_AS": [FixedExecutor(ADMIN_USERNAME)],
},
),
patch(
Expand Down Expand Up @@ -307,7 +307,7 @@ def test_get_async_chart_screenshot_as_fixed_user(self):
patch.dict(
"superset.thumbnails.digest.current_app.config",
{
"THUMBNAIL_EXECUTE_AS": [ExecutorType.FIXED_USER],
"THUMBNAIL_EXECUTE_AS": [FixedExecutor(ADMIN_USERNAME)],
},
),
patch(
Expand Down

0 comments on commit ce4330b

Please sign in to comment.