diff options
author | Jordan Cook <jordan.cook.git@proton.me> | 2022-09-29 15:28:04 -0500 |
---|---|---|
committer | Jordan Cook <jordan.cook.git@proton.me> | 2022-09-30 16:00:16 -0500 |
commit | 747f472e7a50274f45e414c9ee4f8fe70f6f1131 (patch) | |
tree | 9161e6288f3dcdb09ef636e99db470b9f9fcd203 /tests | |
parent | e06d915d12f97a72b932be7dc67ccf4b80077324 (diff) | |
download | requests-cache-747f472e7a50274f45e414c9ee4f8fe70f6f1131.tar.gz |
Add ttl_offset argument for Redis backend
Diffstat (limited to 'tests')
-rw-r--r-- | tests/integration/test_redis.py | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/tests/integration/test_redis.py b/tests/integration/test_redis.py index 83a15d5..c6cb88a 100644 --- a/tests/integration/test_redis.py +++ b/tests/integration/test_redis.py @@ -1,9 +1,10 @@ from unittest.mock import patch import pytest +from redis import StrictRedis from requests_cache.backends import RedisCache, RedisDict, RedisHashDict -from tests.conftest import fail_if_no_connection +from tests.conftest import fail_if_no_connection, httpbin from tests.integration.base_cache_test import BaseCacheTest from tests.integration.base_storage_test import BaseStorageTest @@ -36,3 +37,25 @@ class TestRedisHashDict(TestRedisDict): class TestRedisCache(BaseCacheTest): backend_class = RedisCache + + @patch.object(StrictRedis, 'setex') + def test_ttl(self, mock_setex): + session = self.init_session(expire_after=60) + session.get(httpbin('get')) + call_args = mock_setex.mock_calls[0].args + assert call_args[1] == 3660 # Should be expiration + default offset + + @patch.object(StrictRedis, 'setex') + def test_ttl__offset(self, mock_setex): + session = self.init_session(expire_after=60, ttl_offset=500) + session.get(httpbin('get')) + call_args = mock_setex.mock_calls[0].args + assert call_args[1] == 560 # Should be expiration + custom offset + + @patch.object(StrictRedis, 'setex') + @patch.object(StrictRedis, 'set') + def test_ttl__disabled(self, mock_set, mock_setex): + session = self.init_session(expire_after=60, ttl=False) + session.get(httpbin('get')) + mock_setex.assert_not_called() + mock_set.assert_called() |