summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-02-15 12:47:40 -0600
committerJordan Cook <jordan.cook@pioneer.com>2022-02-15 13:00:52 -0600
commit1f5d6f6ff180e4755e8ac1a69b646a33e2259b23 (patch)
tree8e9a04484bfb986f6a12fb2437e49f4f4ddbd459
parent261bda40a5c2cf804fc40fff7838cc33a8b1b64e (diff)
downloadrequests-cache-1f5d6f6ff180e4755e8ac1a69b646a33e2259b23.tar.gz
Use only integers for expire_after values in tests and docs
-rw-r--r--docs/user_guide/expiration.md6
-rw-r--r--tests/unit/test_session.py20
2 files changed, 13 insertions, 13 deletions
diff --git a/docs/user_guide/expiration.md b/docs/user_guide/expiration.md
index 37bc010..3113604 100644
--- a/docs/user_guide/expiration.md
+++ b/docs/user_guide/expiration.md
@@ -75,10 +75,10 @@ retrieving a new response. If you would like to use expired response data in the
For example:
```python
->>> # Cache a test response that will expire immediately
+>>> # Cache a test response and wait until it's expired
>>> session = CachedSession(stale_if_error=True)
->>> session.get('https://httpbin.org/get', expire_after=0.0001)
->>> time.sleep(0.0001)
+>>> session.get('https://httpbin.org/get', expire_after=1)
+>>> time.sleep(1)
```
Afterward, let's say the page has moved and you get a 404, or the site is experiencing downtime and
diff --git a/tests/unit/test_session.py b/tests/unit/test_session.py
index 09b491f..626231d 100644
--- a/tests/unit/test_session.py
+++ b/tests/unit/test_session.py
@@ -10,7 +10,7 @@ from urllib.parse import urlencode
import pytest
import requests
-from requests import Request
+from requests import Request, RequestException
from requests.structures import CaseInsensitiveDict
from requests_cache import ALL_METHODS, CachedResponse, CachedSession
@@ -154,12 +154,12 @@ def test_response_history(mock_session):
def test_repr(mock_session):
"""Test session and cache string representations"""
- mock_session.expire_after = 10.5
+ mock_session.expire_after = 11
mock_session.cache.responses['key'] = 'value'
mock_session.cache.redirects['key'] = 'value'
mock_session.cache.redirects['key_2'] = 'value'
- assert mock_session.cache.cache_name in repr(mock_session) and '10.5' in repr(mock_session)
+ assert mock_session.cache.cache_name in repr(mock_session) and '11' in repr(mock_session)
assert '2 redirects' in str(mock_session.cache) and '1 responses' in str(mock_session.cache)
@@ -515,9 +515,9 @@ def test_expired_request_error(mock_session):
"""Without stale_if_error (default), if there is an error while re-fetching an expired
response, the request should be re-raised and the expired item deleted"""
mock_session.stale_if_error = False
- mock_session.expire_after = 0.01
+ mock_session.expire_after = 1
mock_session.get(MOCKED_URL)
- time.sleep(0.01)
+ time.sleep(1)
with patch.object(mock_session.cache, 'save_response', side_effect=ValueError):
with pytest.raises(ValueError):
@@ -528,12 +528,12 @@ def test_expired_request_error(mock_session):
def test_stale_if_error__exception(mock_session):
"""With stale_if_error, expect to get old cache data if there is an exception during a request"""
mock_session.stale_if_error = True
- mock_session.expire_after = 0.2
+ mock_session.expire_after = 1
assert mock_session.get(MOCKED_URL).from_cache is False
assert mock_session.get(MOCKED_URL).from_cache is True
- time.sleep(0.2)
- with patch.object(mock_session.cache, 'save_response', side_effect=ValueError):
+ time.sleep(1)
+ with patch.object(mock_session.cache, 'save_response', side_effect=RequestException):
response = mock_session.get(MOCKED_URL)
assert response.from_cache is True and response.is_expired is True
@@ -541,12 +541,12 @@ def test_stale_if_error__exception(mock_session):
def test_stale_if_error__error_code(mock_session):
"""With stale_if_error, expect to get old cache data if a response has an error status code"""
mock_session.stale_if_error = True
- mock_session.expire_after = 0.2
+ mock_session.expire_after = 1
mock_session.allowable_codes = (200, 404)
assert mock_session.get(MOCKED_URL_404).from_cache is False
- time.sleep(0.2)
+ time.sleep(1)
response = mock_session.get(MOCKED_URL_404)
assert response.from_cache is True and response.is_expired is True