summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2022-12-13 18:37:04 -0600
committerJordan Cook <jordan.cook.git@proton.me>2022-12-30 14:46:02 -0600
commit94a4449cdc05e1a1460a50f8d696f8032223558b (patch)
tree5442039d47d91723068776c1395996dc25a7037c /tests
parente8ea4ca58845afeda358c31c15dcdb28b2b62896 (diff)
downloadrequests-cache-94a4449cdc05e1a1460a50f8d696f8032223558b.tar.gz
Make CachedResponse.cache_key available from all cache access methods
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/base_storage_test.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/tests/integration/base_storage_test.py b/tests/integration/base_storage_test.py
index 4e0f217..4070492 100644
--- a/tests/integration/base_storage_test.py
+++ b/tests/integration/base_storage_test.py
@@ -6,6 +6,7 @@ import pytest
from attrs import define, field
from requests_cache.backends import BaseStorage
+from requests_cache.models import CachedResponse
from tests.conftest import CACHE_NAME
@@ -62,6 +63,16 @@ class BaseStorageTest:
assert list(cache.items()) == [(f'key_{i}', f'value_{i}')]
assert dict(cache) == {f'key_{i}': f'value_{i}'}
+ def test_cache_key(self):
+ """The cache_key attribute should be available on responses returned from all
+ mapping/collection methods
+ """
+ cache = self.init_cache()
+ cache['key'] = CachedResponse()
+ assert cache['key'].cache_key == 'key'
+ assert list(cache.values())[0].cache_key == 'key'
+ assert list(cache.items())[0][1].cache_key == 'key'
+
def test_del(self):
"""Some more tests to ensure ``delitem`` deletes only the expected items"""
cache = self.init_cache()