Skip to content

Commit

Permalink
added etag testcases to red_test
Browse files Browse the repository at this point in the history
  • Loading branch information
daftshady committed Mar 5, 2015
1 parent 8db1f66 commit 89e153f
Showing 1 changed file with 81 additions and 1 deletion.
82 changes: 81 additions & 1 deletion maint/test/redbot/red_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,21 @@ def get(self):
yield gen.Task(self.flush)
self.finish()

class CacheHandler(RequestHandler):
def get(self, computed_etag):
self.write(computed_etag)

def compute_etag(self):
return self._write_buffer[0]

class TestMixin(object):
def get_handlers(self):
return [
('/hello', HelloHandler),
('/redirect(/.*)', RedirectHandler),
('/post', PostHandler),
('/chunked', ChunkedHandler),
('/cache/(.*)', CacheHandler),
]

def get_app_kwargs(self):
Expand Down Expand Up @@ -70,7 +78,6 @@ def check_url(self, path, method='GET', body=None, headers=None,
raise red.response.http_error.res_error
else:
raise Exception("unknown error; incomplete response")

self.assertEqual(int(red.response.status_code), expected_status)

allowed_warnings = (allowed_warnings or []) + self.get_allowed_warnings()
Expand Down Expand Up @@ -149,6 +156,79 @@ def test_post(self):
def test_chunked(self):
self.check_url('/chunked')

def test_strong_etag_match(self):
computed_etag = '"xyzzy"'
etags = '"xyzzy"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=304)

def test_multiple_strong_etag_match(self):
computed_etag = '"xyzzy1"'
etags = '"xyzzy1", "xyzzy2"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=304)

def test_strong_etag_not_match(self):
computed_etag = '"xyzzy"'
etags = '"xyzzy1"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=200)

def test_multiple_strong_etag_not_match(self):
computed_etag = '"xyzzy"'
etags = '"xyzzy1", "xyzzy2"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=200)

def test_wildcard_etag(self):
computed_etag = '"xyzzy"'
etags = '*'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=304,
allowed_warnings=[rs.MISSING_HDRS_304])

def test_weak_etag_match(self):
computed_etag = '"xyzzy1"'
etags = 'W/"xyzzy1"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=304)

def test_multiple_weak_etag_match(self):
computed_etag = '"xyzzy2"'
etags = 'W/"xyzzy1", W/"xyzzy2"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=304)

def test_weak_etag_not_match(self):
computed_etag = '"xyzzy2"'
etags = 'W/"xyzzy1"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=200)

def test_multiple_weak_etag_not_match(self):
computed_etag = '"xyzzy3"'
etags = 'W/"xyzzy1", W/"xyzzy2"'
self.check_url(
'/cache/' + computed_etag, method='GET',
headers=[('If-None-Match', etags)],
expected_status=200)

class DefaultHTTPTest(AsyncHTTPTestCase, LogTrapTestCase, TestMixin):
def get_app(self):
return Application(self.get_handlers(), **self.get_app_kwargs())
Expand Down

0 comments on commit 89e153f

Please sign in to comment.