diff options
author | Jordan Cook <jordan.cook@pioneer.com> | 2021-04-10 10:29:09 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook@pioneer.com> | 2021-04-10 10:29:09 -0500 |
commit | 624e0c7f3408a24b70409b663227db07d08c9dd1 (patch) | |
tree | 2ca951031332f6da2403c25172f912771cb8c14b | |
parent | 76fb97de2c9cf27e36268f4ae7c23c535e954c19 (diff) | |
download | requests-cache-624e0c7f3408a24b70409b663227db07d08c9dd1.tar.gz |
Add remove_old_entries() back to BaseCache as an alias with a DeprecationWarning
-rw-r--r-- | requests_cache/backends/base.py | 5 | ||||
-rw-r--r-- | tests/unit/test_cache.py | 8 |
2 files changed, 12 insertions, 1 deletions
diff --git a/requests_cache/backends/base.py b/requests_cache/backends/base.py index bca2700..1021b3d 100644 --- a/requests_cache/backends/base.py +++ b/requests_cache/backends/base.py @@ -124,6 +124,11 @@ class BaseCache: if response.is_expired: self.delete(key) + def remove_old_entries(self, *args, **kwargs): + msg = 'BaseCache.remove_old_entries() is deprecated; ' 'please use CachedSession.remove_expired_responses()' + warnings.warn(DeprecationWarning(msg)) + self.remove_expired_responses(*args, **kwargs) + def create_key(self, request: requests.PreparedRequest, **kwargs) -> str: """Create a normalized cache key from a request object""" return create_key(request, self._ignored_parameters, self._include_get_headers, **kwargs) diff --git a/tests/unit/test_cache.py b/tests/unit/test_cache.py index 5515efc..e51e8d9 100644 --- a/tests/unit/test_cache.py +++ b/tests/unit/test_cache.py @@ -56,7 +56,13 @@ def test_init_backend_class(): def test_import_compat(): """Just make sure that we can still import from requests_cache.core""" - from requests_cache.core import CachedSession, install_cache # noqa: F401 + with pytest.deprecated_call(): + from requests_cache.core import CachedSession, install_cache # noqa: F401 + + +def test_method_compat(mock_session): + with pytest.deprecated_call(): + mock_session.cache.remove_old_entries() @pytest.mark.parametrize('method', ALL_METHODS) |