From 008428d39aa930c7213630fc74f6639dbd6d81ac Mon Sep 17 00:00:00 2001 From: Thomas Neidhart Date: Mon, 2 Oct 2023 20:28:20 +0200 Subject: [PATCH] Move disabled test to base class. --- test/integration/base_backend_test.py | 25 +++++++++++++++++++++++++ test/integration/test_filesystem.py | 19 +------------------ 2 files changed, 26 insertions(+), 18 deletions(-) diff --git a/test/integration/base_backend_test.py b/test/integration/base_backend_test.py index 41cfd5f..ecb5657 100644 --- a/test/integration/base_backend_test.py +++ b/test/integration/base_backend_test.py @@ -283,3 +283,28 @@ async def test_serializer__itsdangerous(self): session.cache.responses._serializer.secret_keys = ['a different key'] with pytest.raises(BadSignature): await session.cache.responses.read('key') + + async def test_disabled(self): + """With a disabled CachedSession, responses should not come from the cache + and the cache should not be modified + """ + async with self.init_session() as session: + # first request shall populate the cache + response = await session.request("GET", httpbin('cache/0')) + + assert response.from_cache is False + assert await session.cache.responses.size() == 1 + + # second request shall come from the cache + response = await session.request("GET", httpbin('cache/0')) + + assert response.from_cache is True + assert await session.cache.responses.size() == 1 + + # now disable the cache, the response should not come from the cache + # but the cache should be unmodified afterward. + async with session.disabled(): + response = await session.request("GET", httpbin('cache/0')) + + assert response.from_cache is False + assert await session.cache.responses.size() == 1 diff --git a/test/integration/test_filesystem.py b/test/integration/test_filesystem.py index a4cd26f..dab975b 100644 --- a/test/integration/test_filesystem.py +++ b/test/integration/test_filesystem.py @@ -9,7 +9,7 @@ from aiohttp_client_cache.backends.base import BaseCache from aiohttp_client_cache.backends.filesystem import FileBackend, FileCache from aiohttp_client_cache.session import CachedSession -from test.conftest import CACHE_NAME, httpbin +from test.conftest import CACHE_NAME from test.integration import BaseBackendTest, BaseStorageTest @@ -56,23 +56,6 @@ class TestFileBackend(BaseBackendTest): async def test_gather(self): super().test_gather() - async def test_disabled(self): - async with self.init_session() as session: - response = await session.request("GET", httpbin('cache/0')) - - assert response.from_cache is False - assert await session.cache.responses.size() == 1 - - response = await session.request("GET", httpbin('cache/0')) - - assert response.from_cache is True - assert await session.cache.responses.size() == 1 - - async with session.disabled(): - response = await session.request("GET", httpbin('cache/0')) - assert response.from_cache is False - assert await session.cache.responses.size() == 1 - async def test_redirect_cache_path(self): async with self.init_session() as session: assert isinstance(session, CachedSession)