sadpandajoe commented on code in PR #43945:
URL: https://github.com/apache/superset/pull/43945#discussion_r3959476700


##########
tests/unit_tests/extensions/test_metastore_cache.py:
##########
@@ -0,0 +1,92 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from importlib.metadata import version
+from uuid import UUID
+
+import pytest
+from flask import Flask
+from flask_caching import Cache
+from packaging.version import Version
+
+from superset.extensions.metastore_cache import SupersetMetastoreCache
+from superset.key_value.types import JsonKeyValueCodec
+from superset.key_value.utils import get_uuid_namespace
+
+
+def test_metastore_cache_constructor() -> None:
+    """Direct construction remains compatible without extra backend options."""
+    namespace = UUID("ee173d1b-ccf3-40aa-941c-985c15224496")
+    codec = JsonKeyValueCodec()
+
+    cache = SupersetMetastoreCache(namespace, codec)
+
+    assert cache.default_timeout == 300
+    assert cache.namespace == namespace
+    assert cache.codec is codec
+
+
[email protected]("ignore_errors", [False, True])
+def test_metastore_cache_init_app(ignore_errors: bool) -> None:
+    """Flask-Caching can initialize the backend with its generated options."""
+    app = Flask(__name__)
+    app.config["HASH_ALGORITHM"] = "sha256"
+    codec = JsonKeyValueCodec()
+    cache = Cache()
+
+    cache.init_app(
+        app,
+        {
+            "CACHE_TYPE": 
"superset.extensions.metastore_cache.SupersetMetastoreCache",
+            "CACHE_DEFAULT_TIMEOUT": 600,
+            "CACHE_KEY_PREFIX": "filter_state",
+            "CACHE_IGNORE_ERRORS": ignore_errors,
+            "CODEC": codec,
+        },
+    )
+
+    with app.app_context():
+        backend = cache.cache
+        assert isinstance(backend, SupersetMetastoreCache)
+        assert backend.default_timeout == 600
+        assert backend.namespace == get_uuid_namespace("filter_state", app)
+        assert backend.codec is codec
+        if Version(version("flask-caching")) >= Version("2.5.0"):

Review Comment:
   The compatibility assertions only run when Flask-Caching is at least 2.5, 
but the checked-in test requirements still pin 2.4.1, so this test is skipped 
in the normal unit-test environment. That leaves the 2.5 constructor and 
memoize-key compatibility path untested by CI. Could we add a focused 2.5 test 
environment or update the dependency set that exercises this regression?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to