Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def permalink(self, env, start_response):
return [b"The permanent resource"]

def multiple_choices(self, env, start_response):
headers = [("Link", "/permalink")]
headers = [("Link", "/permalink"), ("Cache-Control", "max-age=5000")]
start_response("300 Multiple Choices", headers)
return [b"See: /permalink"]

Expand Down
17 changes: 13 additions & 4 deletions tests/test_redirects.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,28 @@ def setup_method(self):
self.sess = CacheControl(requests.Session())

def test_multiple_choices_is_cacheable(self, url):
self.sess.get(url + "multiple_choices_redirect", allow_redirects=False)
first = self.sess.get(url + "multiple_choices", allow_redirects=False)
assert first.status_code == 300
assert not first.from_cache

resp = self.sess.get(url + "multiple_choices_redirect", allow_redirects=False)
resp = self.sess.get(url + "multiple_choices", allow_redirects=False)

assert resp.status_code == 300
assert resp.from_cache
assert resp.content == first.content

def test_bust_cache_on_redirect(self, url):
self.sess.get(url + "multiple_choices_redirect", allow_redirects=False)
self.sess.get(url + "multiple_choices", allow_redirects=False)

cached = self.sess.get(url + "multiple_choices", allow_redirects=False)
assert cached.status_code == 300
assert cached.from_cache

resp = self.sess.get(
url + "multiple_choices_redirect",
url + "multiple_choices",
headers={"cache-control": "no-cache"},
allow_redirects=False,
)

assert resp.status_code == 300
assert not resp.from_cache