Skip to content

Commit

Permalink
Move disabled test to base class.
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Oct 2, 2023
1 parent 8a628bf commit 008428d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
25 changes: 25 additions & 0 deletions test/integration/base_backend_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
19 changes: 1 addition & 18 deletions test/integration/test_filesystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 008428d

Please sign in to comment.