mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
refactor(test): add login_as_admin in global conftest (#20703)
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
"""Unit tests for Superset"""
|
||||
from typing import Dict, Any
|
||||
|
||||
from tests.integration_tests.test_app import app # noqa
|
||||
import pytest
|
||||
|
||||
from superset.extensions import cache_manager, db
|
||||
from superset.models.cache import CacheKey
|
||||
@@ -26,23 +26,25 @@ from superset.utils.core import get_example_default_schema
|
||||
from tests.integration_tests.base_tests import (
|
||||
SupersetTestCase,
|
||||
post_assert_metric,
|
||||
test_client,
|
||||
logged_in_admin,
|
||||
) # noqa
|
||||
)
|
||||
|
||||
|
||||
def invalidate(params: Dict[str, Any]):
|
||||
return post_assert_metric(
|
||||
test_client, "api/v1/cachekey/invalidate", params, "invalidate"
|
||||
)
|
||||
@pytest.fixture
|
||||
def invalidate(test_client, login_as_admin):
|
||||
def _invalidate(params: Dict[str, Any]):
|
||||
return post_assert_metric(
|
||||
test_client, "api/v1/cachekey/invalidate", params, "invalidate"
|
||||
)
|
||||
|
||||
return _invalidate
|
||||
|
||||
|
||||
def test_invalidate_cache(logged_in_admin):
|
||||
def test_invalidate_cache(invalidate):
|
||||
rv = invalidate({"datasource_uids": ["3__table"]})
|
||||
assert rv.status_code == 201
|
||||
|
||||
|
||||
def test_invalidate_existing_cache(logged_in_admin):
|
||||
def test_invalidate_existing_cache(invalidate):
|
||||
db.session.add(CacheKey(cache_key="cache_key", datasource_uid="3__table"))
|
||||
db.session.commit()
|
||||
cache_manager.cache.set("cache_key", "value")
|
||||
@@ -56,7 +58,7 @@ def test_invalidate_existing_cache(logged_in_admin):
|
||||
)
|
||||
|
||||
|
||||
def test_invalidate_cache_empty_input(logged_in_admin):
|
||||
def test_invalidate_cache_empty_input(invalidate):
|
||||
rv = invalidate({"datasource_uids": []})
|
||||
assert rv.status_code == 201
|
||||
|
||||
@@ -67,7 +69,7 @@ def test_invalidate_cache_empty_input(logged_in_admin):
|
||||
assert rv.status_code == 201
|
||||
|
||||
|
||||
def test_invalidate_cache_bad_request(logged_in_admin):
|
||||
def test_invalidate_cache_bad_request(invalidate):
|
||||
rv = invalidate(
|
||||
{
|
||||
"datasource_uids": [],
|
||||
@@ -93,7 +95,7 @@ def test_invalidate_cache_bad_request(logged_in_admin):
|
||||
assert rv.status_code == 400
|
||||
|
||||
|
||||
def test_invalidate_existing_caches(logged_in_admin):
|
||||
def test_invalidate_existing_caches(invalidate):
|
||||
schema = get_example_default_schema() or ""
|
||||
bn = SupersetTestCase.get_birth_names_dataset()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user