From 94a4449cdc05e1a1460a50f8d696f8032223558b Mon Sep 17 00:00:00 2001 From: Jordan Cook Date: Tue, 13 Dec 2022 18:37:04 -0600 Subject: Make CachedResponse.cache_key available from all cache access methods --- tests/integration/base_storage_test.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tests') 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() -- cgit v1.2.1