mirror of
https://github.com/apache/superset.git
synced 2026-04-20 08:34:37 +00:00
refactor: reduce number of api calls needed to fetch favorite status for charts and dashboards (#11502)
This commit is contained in:
@@ -35,7 +35,7 @@ from tests.fixtures.unicode_dashboard import load_unicode_dashboard_with_slice
|
||||
from tests.test_app import app
|
||||
from superset.connectors.connector_registry import ConnectorRegistry
|
||||
from superset.extensions import db, security_manager
|
||||
from superset.models.core import FavStar
|
||||
from superset.models.core import FavStar, FavStarClassName
|
||||
from superset.models.dashboard import Dashboard
|
||||
from superset.models.slice import Slice
|
||||
from superset.utils import core as utils
|
||||
@@ -776,6 +776,35 @@ class TestChartApi(SupersetTestCase, ApiOwnersTestCaseMixin):
|
||||
assert rv.status_code == 200
|
||||
assert len(expected_models) == data["count"]
|
||||
|
||||
@pytest.mark.usefixtures("create_charts")
|
||||
def test_get_current_user_favorite_status(self):
|
||||
"""
|
||||
Dataset API: Test get current user favorite stars
|
||||
"""
|
||||
admin = self.get_user("admin")
|
||||
users_favorite_ids = [
|
||||
star.obj_id
|
||||
for star in db.session.query(FavStar.obj_id)
|
||||
.filter(
|
||||
and_(
|
||||
FavStar.user_id == admin.id,
|
||||
FavStar.class_name == FavStarClassName.CHART,
|
||||
)
|
||||
)
|
||||
.all()
|
||||
]
|
||||
|
||||
assert users_favorite_ids
|
||||
arguments = [s.id for s in db.session.query(Slice.id).all()]
|
||||
self.login(username="admin")
|
||||
uri = f"api/v1/chart/favorite_status/?q={prison.dumps(arguments)}"
|
||||
rv = self.client.get(uri)
|
||||
data = json.loads(rv.data.decode("utf-8"))
|
||||
assert rv.status_code == 200
|
||||
for res in data["result"]:
|
||||
if res["id"] in users_favorite_ids:
|
||||
assert res["value"]
|
||||
|
||||
@pytest.mark.usefixtures("load_unicode_dashboard_with_slice")
|
||||
def test_get_charts_page(self):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user