mirror of
https://github.com/apache/superset.git
synced 2026-04-19 08:04:53 +00:00
feat(docker): Add pytest support to docker-compose-light.yml (#34373)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
committed by
GitHub
parent
6f5d9c989a
commit
246181a546
@@ -26,7 +26,9 @@ from flask.ctx import AppContext
|
||||
from freezegun import freeze_time
|
||||
|
||||
from superset.extensions.metastore_cache import SupersetMetastoreCache
|
||||
from superset.key_value.exceptions import KeyValueCodecEncodeException
|
||||
from superset.key_value.exceptions import (
|
||||
KeyValueCreateFailedError,
|
||||
)
|
||||
from superset.key_value.types import (
|
||||
JsonKeyValueCodec,
|
||||
KeyValueCodec,
|
||||
@@ -53,6 +55,10 @@ def cache() -> SupersetMetastoreCache:
|
||||
|
||||
|
||||
def test_caching_flow(app_context: AppContext, cache: SupersetMetastoreCache) -> None:
|
||||
# Clean up any existing keys first to ensure idempotency
|
||||
cache.delete(FIRST_KEY)
|
||||
cache.delete(SECOND_KEY)
|
||||
|
||||
assert cache.has(FIRST_KEY) is False
|
||||
assert cache.add(FIRST_KEY, FIRST_KEY_INITIAL_VALUE) is True
|
||||
assert cache.has(FIRST_KEY) is True
|
||||
@@ -70,8 +76,14 @@ def test_caching_flow(app_context: AppContext, cache: SupersetMetastoreCache) ->
|
||||
assert cache.has(SECOND_KEY)
|
||||
assert cache.get(SECOND_KEY) == SECOND_VALUE
|
||||
|
||||
# Clean up after test as well for good measure
|
||||
cache.delete(SECOND_KEY)
|
||||
|
||||
|
||||
def test_expiry(app_context: AppContext, cache: SupersetMetastoreCache) -> None:
|
||||
# Clean up any existing keys first to ensure idempotency
|
||||
cache.delete(FIRST_KEY)
|
||||
|
||||
delta = timedelta(days=90)
|
||||
dttm = datetime(2022, 3, 18, 0, 0, 0)
|
||||
|
||||
@@ -97,13 +109,16 @@ def test_expiry(app_context: AppContext, cache: SupersetMetastoreCache) -> None:
|
||||
assert cache.add(FIRST_KEY, SECOND_VALUE, int(delta.total_seconds())) is True
|
||||
assert cache.get(FIRST_KEY) == SECOND_VALUE
|
||||
|
||||
# Clean up after test as well for good measure
|
||||
cache.delete(FIRST_KEY)
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"input_,codec,expected_result",
|
||||
[
|
||||
({"foo": "bar"}, JsonKeyValueCodec(), {"foo": "bar"}),
|
||||
(("foo", "bar"), JsonKeyValueCodec(), ["foo", "bar"]),
|
||||
(complex(1, 1), JsonKeyValueCodec(), KeyValueCodecEncodeException()),
|
||||
(complex(1, 1), JsonKeyValueCodec(), KeyValueCreateFailedError()),
|
||||
({"foo": "bar"}, PickleKeyValueCodec(), {"foo": "bar"}),
|
||||
(("foo", "bar"), PickleKeyValueCodec(), ("foo", "bar")),
|
||||
(complex(1, 1), PickleKeyValueCodec(), complex(1, 1)),
|
||||
@@ -122,6 +137,10 @@ def test_codec(
|
||||
default_timeout=600,
|
||||
codec=codec,
|
||||
)
|
||||
|
||||
# Clean up any existing keys first to ensure idempotency
|
||||
cache.delete(FIRST_KEY)
|
||||
|
||||
cm = (
|
||||
pytest.raises(type(expected_result))
|
||||
if isinstance(expected_result, Exception)
|
||||
@@ -130,3 +149,6 @@ def test_codec(
|
||||
with cm:
|
||||
cache.set(FIRST_KEY, input_)
|
||||
assert cache.get(FIRST_KEY) == expected_result
|
||||
|
||||
# Clean up after test as well for good measure
|
||||
cache.delete(FIRST_KEY)
|
||||
|
||||
Reference in New Issue
Block a user