Skip to content

Commit b3ab611

Browse files
test: Override MongoDB sanitization tests to handle default passthrough behavior
The default sanitization behavior is now PassthroughStrategy (no sanitization). This change updates the Memcached tests to: 1. Add a sanitizing_store fixture that uses MemcachedV1KeySanitizationStrategy 2. Override test_long_collection_name and test_long_key_name to test both: - Default store (expects exception due to memcached's key length limits) - Sanitizing store (succeeds with V1 strategy) This follows the same pattern as MongoDB and Elasticsearch tests. Co-authored-by: William Easton <strawgate@users.noreply.github.com>
1 parent 85d85c7 commit b3ab611

File tree

1 file changed

+29
-1
lines changed

1 file changed

+29
-1
lines changed

key-value/key-value-aio/tests/stores/memcached/test_memcached.py

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from typing_extensions import override
1111

1212
from key_value.aio.stores.base import BaseStore
13-
from key_value.aio.stores.memcached import MemcachedStore
13+
from key_value.aio.stores.memcached import MemcachedStore, MemcachedV1KeySanitizationStrategy
1414
from tests.conftest import docker_container, should_skip_docker_tests
1515
from tests.stores.base import BaseStoreTests, ContextManagerStoreTestMixin
1616

@@ -65,10 +65,38 @@ async def store(self, setup_memcached: None) -> MemcachedStore:
6565
_ = await store._client.flush_all() # pyright: ignore[reportPrivateUsage]
6666
return store
6767

68+
@pytest.fixture
69+
async def sanitizing_store(self, setup_memcached: None) -> MemcachedStore:
70+
store = MemcachedStore(
71+
host=MEMCACHED_HOST,
72+
port=MEMCACHED_PORT,
73+
key_sanitization_strategy=MemcachedV1KeySanitizationStrategy(),
74+
)
75+
_ = await store._client.flush_all() # pyright: ignore[reportPrivateUsage]
76+
return store
77+
6878
@pytest.mark.skip(reason="Distributed Caches are unbounded")
6979
@override
7080
async def test_not_unbounded(self, store: BaseStore): ...
7181

82+
@override
83+
async def test_long_collection_name(self, store: MemcachedStore, sanitizing_store: MemcachedStore): # pyright: ignore[reportIncompatibleMethodOverride]
84+
"""Tests that a long collection name will not raise an error."""
85+
with pytest.raises(Exception): # noqa: B017, PT011
86+
await store.put(collection="test_collection" * 100, key="test_key", value={"test": "test"})
87+
88+
await sanitizing_store.put(collection="test_collection" * 100, key="test_key", value={"test": "test"})
89+
assert await sanitizing_store.get(collection="test_collection" * 100, key="test_key") == {"test": "test"}
90+
91+
@override
92+
async def test_long_key_name(self, store: MemcachedStore, sanitizing_store: MemcachedStore): # pyright: ignore[reportIncompatibleMethodOverride]
93+
"""Tests that a long key name will not raise an error."""
94+
with pytest.raises(Exception): # noqa: B017, PT011
95+
await store.put(collection="test_collection", key="test_key" * 100, value={"test": "test"})
96+
97+
await sanitizing_store.put(collection="test_collection", key="test_key" * 100, value={"test": "test"})
98+
assert await sanitizing_store.get(collection="test_collection", key="test_key" * 100) == {"test": "test"}
99+
72100
@pytest.fixture
73101
async def memcached_client(self, store: MemcachedStore) -> Client:
74102
return store._client # pyright: ignore[reportPrivateUsage]

0 commit comments

Comments
 (0)