From e36f5da7fa0934b544f5592c21658e80bc5389bf Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Tue, 3 Oct 2023 20:08:14 +0200 Subject: [PATCH 1/3] Enable gather test which seems to work now. --- test/integration/test_redis.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/test/integration/test_redis.py b/test/integration/test_redis.py index 623a4ca6..eedcd14e 100644 --- a/test/integration/test_redis.py +++ b/test/integration/test_redis.py @@ -36,7 +36,3 @@ class TestRedisCache(BaseStorageTest): class TestRedisBackend(BaseBackendTest): backend_class = RedisBackend - - @pytest.mark.skip(reason='Test not yet working for Redis backend') - async def test_gather(self): - super().test_gather() From 08583dbf4cd826ecdaaa4268dcf209b541f9a3cd Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Tue, 3 Oct 2023 20:09:04 +0200 Subject: [PATCH 2/3] Ensure that all method calls for a cache happen within the contextmanager. --- test/integration/base_storage_test.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/integration/base_storage_test.py b/test/integration/base_storage_test.py index a822bd07..ed49b63b 100644 --- a/test/integration/base_storage_test.py +++ b/test/integration/base_storage_test.py @@ -83,8 +83,8 @@ async def test_keys_values(self): for k, v in test_data.items(): await cache.write(k, v) - assert sorted([k async for k in cache.keys()]) == sorted(test_data.keys()) - assert sorted([v async for v in cache.values()]) == sorted(test_data.values()) + assert sorted([k async for k in cache.keys()]) == sorted(test_data.keys()) + assert sorted([v async for v in cache.values()]) == sorted(test_data.values()) async def test_size(self): async with self.init_cache() as cache: @@ -92,7 +92,7 @@ async def test_size(self): for k, v in self.test_data.items(): await cache.write(k, v) - assert await cache.size() == len(self.test_data) + assert await cache.size() == len(self.test_data) async def test_clear(self): async with self.init_cache() as cache: From 8f787d0db8c52a05615718f7c2a61c9e6a677615 Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Tue, 3 Oct 2023 20:10:29 +0200 Subject: [PATCH 3/3] Properly close the sqlite backend during tests, use temp directory for pickle cache. --- test/integration/test_sqlite.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/integration/test_sqlite.py b/test/integration/test_sqlite.py index 10fcab55..4badcb1a 100644 --- a/test/integration/test_sqlite.py +++ b/test/integration/test_sqlite.py @@ -1,11 +1,10 @@ import asyncio import os from tempfile import gettempdir -from unittest.mock import patch +from unittest.mock import MagicMock, patch import pytest -from aiohttp_client_cache.backends import CacheBackend from aiohttp_client_cache.backends.sqlite import SQLiteBackend, SQLiteCache, SQLitePickleCache from test.conftest import CACHE_NAME, httpbin, skip_37 from test.integration import BaseBackendTest, BaseStorageTest @@ -139,6 +138,7 @@ async def test_close(self): class TestSQLitePickleCache(BaseStorageTest): + init_kwargs = {'use_temp': True} picklable = True storage_class = SQLitePickleCache @@ -148,10 +148,12 @@ class TestSQLiteBackend(BaseBackendTest): init_kwargs = {'use_temp': True} @skip_37 - @patch.object(CacheBackend, 'close') - async def test_autoclose__default(self, mock_close): + async def test_autoclose__default(self): """By default, the backend should be closed when the session is closed""" async with self.init_session() as session: + mock_close = MagicMock(wraps=session.cache.close) + session.cache.close = mock_close + await session.get(httpbin('get')) mock_close.assert_called_once()