summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook.git@proton.me>2023-03-13 12:26:27 -0500
committerJordan Cook <jordan.cook.git@proton.me>2023-03-24 18:50:18 -0500
commit5bcb137ff944533210036d5fcefe0a5f87cde96c (patch)
treead8c7daec7cfab477e6129c7e4ff99b8000822ac /tests
parent0dcf40989503df7041eb9f0c4789aecea78cbd5c (diff)
downloadrequests-cache-5bcb137ff944533210036d5fcefe0a5f87cde96c.tar.gz
Ignore Cache-Control: must-revalidate and no-cache when cache_control=False
Diffstat (limited to 'tests')
-rw-r--r--tests/unit/policy/test_actions.py23
1 files changed, 16 insertions, 7 deletions
diff --git a/tests/unit/policy/test_actions.py b/tests/unit/policy/test_actions.py
index 4ea133c..c50e212 100644
--- a/tests/unit/policy/test_actions.py
+++ b/tests/unit/policy/test_actions.py
@@ -184,24 +184,33 @@ def test_update_from_cached_response__revalidate(response_headers, expected_vali
@pytest.mark.parametrize(
- 'request_headers, response_headers',
+ 'response_headers',
[
- ({}, {'Cache-Control': 'no-cache'}),
- ({}, {'Cache-Control': 'max-age=0,must-revalidate'}),
+ {'Cache-Control': 'no-cache'},
+ {'Cache-Control': 'max-age=0,must-revalidate'},
],
)
-def test_update_from_cached_response__refresh(request_headers, response_headers):
+@pytest.mark.parametrize('cache_control', [True, False])
+def test_update_from_cached_response__force_revalidate(cache_control, response_headers):
"""Conditional request headers should be added if requested by response headers, even if the
response is not expired
"""
actions = CacheActions.from_request(
- 'key', Request(url='https://img.site.com/base/img.jpg', headers=request_headers)
+ 'key',
+ request=Request(url='https://img.site.com/base/img.jpg', headers={}),
+ settings=CacheSettings(cache_control=cache_control),
)
cached_response = CachedResponse(headers={'ETag': ETAG, **response_headers}, expires=None)
actions.update_from_cached_response(cached_response)
- assert actions.send_request is True
- assert actions._validation_headers == {'If-None-Match': ETAG}
+
+ # cache_control=False overrides revalidation in this case
+ if cache_control is False:
+ assert actions.send_request is False
+ assert not actions._validation_headers
+ else:
+ assert actions.send_request is True
+ assert actions._validation_headers == {'If-None-Match': ETAG}
def test_update_from_cached_response__no_revalidation():