|
10 | 10 | from typing_extensions import override |
11 | 11 |
|
12 | 12 | 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 |
14 | 14 | from tests.conftest import docker_container, should_skip_docker_tests |
15 | 15 | from tests.stores.base import BaseStoreTests, ContextManagerStoreTestMixin |
16 | 16 |
|
@@ -65,10 +65,38 @@ async def store(self, setup_memcached: None) -> MemcachedStore: |
65 | 65 | _ = await store._client.flush_all() # pyright: ignore[reportPrivateUsage] |
66 | 66 | return store |
67 | 67 |
|
| 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 | + |
68 | 78 | @pytest.mark.skip(reason="Distributed Caches are unbounded") |
69 | 79 | @override |
70 | 80 | async def test_not_unbounded(self, store: BaseStore): ... |
71 | 81 |
|
| 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 | + |
72 | 100 | @pytest.fixture |
73 | 101 | async def memcached_client(self, store: MemcachedStore) -> Client: |
74 | 102 | return store._client # pyright: ignore[reportPrivateUsage] |
|
0 commit comments