summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2022-04-18 15:04:51 -0500
committerJordan Cook <jordan.cook@pioneer.com>2022-04-18 15:04:51 -0500
commitea326d16d82d86f4fda14f83745a5a399824257d (patch)
tree708407dead63c0411ab0f0e62dab0837559ec67d /tests
parent8eaa78848f4f71e687c56609d49302c03775bb2a (diff)
downloadrequests-cache-ea326d16d82d86f4fda14f83745a5a399824257d.tar.gz
Add support for Cache-Control: max-stale and min-fresh
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/policy/test_actions.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/unit/policy/test_actions.py b/tests/unit/policy/test_actions.py
index f70cc8d..e5ac44b 100644
--- a/tests/unit/policy/test_actions.py
+++ b/tests/unit/policy/test_actions.py
@@ -200,6 +200,38 @@ def test_update_from_cached_response__ignored():
assert actions._validation_headers == {}
+@pytest.mark.parametrize('max_stale, rejected', [(5, True), (15, False)])
+def test_is_expired__max_stale(max_stale, rejected):
+ """For a response that expired 10 seconds ago, it may be either accepted or rejected based on
+ max-stale
+ """
+ request = Request(
+ url='https://img.site.com/base/img.jpg',
+ headers={'Cache-Control': f'max-stale={max_stale}'},
+ )
+ actions = CacheActions.from_request('key', request)
+ cached_response = CachedResponse(
+ expires=datetime.utcnow() - timedelta(seconds=10),
+ )
+ assert actions._is_expired(cached_response) is rejected
+
+
+@pytest.mark.parametrize('min_fresh, rejected', [(5, False), (15, True)])
+def test_is_expired__min_fresh(min_fresh, rejected):
+ """For a response that expires in 10 seconds, it may be either accepted or rejected based on
+ min-fresh
+ """
+ request = Request(
+ url='https://img.site.com/base/img.jpg',
+ headers={'Cache-Control': f'min-fresh={min_fresh}'},
+ )
+ actions = CacheActions.from_request('key', request)
+ cached_response = CachedResponse(
+ expires=datetime.utcnow() + timedelta(seconds=10),
+ )
+ assert actions._is_expired(cached_response) is rejected
+
+
@pytest.mark.parametrize(
'headers, expected_expiration',
[