Skip to content

Commit 44b5974

Browse files
committed
add failing heuristic test for 301 and 304 response
1 parent 4746b90 commit 44b5974

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests/conftest.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ def update_etag(self, env, start_response):
5959
start_response('200 OK', headers)
6060
return [pformat(env).encode("utf8")]
6161

62+
def conditional_get(self, env, start_response):
63+
return start_response('304 Not Modified', [])
64+
6265
def etag(self, env, start_response):
6366
headers = [
6467
('Etag', self.etag_string),

tests/test_expires_heuristics.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ def test_no_header_change_means_no_warning_header(self, url):
3636
assert not self.heuristic.warning.called
3737

3838

39+
class TestHeuristicWith3xxResponse(object):
40+
def setup(self):
41+
42+
class DummyHeuristic(BaseHeuristic):
43+
def update_headers(self, resp):
44+
return {'x-dummy-header': 'foobar'}
45+
46+
self.sess = CacheControl(Session(), heuristic=DummyHeuristic())
47+
48+
def test_heuristic_applies_to_301(self, url):
49+
the_url = url + 'permanent_redirect'
50+
resp = self.sess.get(the_url)
51+
assert 'x-dummy-header' in resp.headers
52+
53+
def test_heuristic_applies_to_304(self, url):
54+
the_url = url + 'conditional_get'
55+
resp = self.sess.get(the_url)
56+
assert 'x-dummy-header' in resp.headers
57+
58+
3959
class TestUseExpiresHeuristic(object):
4060

4161
def test_expires_heuristic_arg(self):

0 commit comments

Comments
 (0)