Fixed the size limit tests in Python 3

- None cannot be compared to an integer in Python 3
- In Python 3 a request body must be bytes

bp python3

Change-Id: If3944f84d41f54089a8d245848c3012d566385f1
This commit is contained in:
David Stanek 2014-03-30 12:58:59 +00:00
parent 025a404ac3
commit 410ddb826f
3 changed files with 10 additions and 9 deletions

View File

@ -220,13 +220,13 @@ class RequestBodySizeLimiter(wsgi.Middleware):
@webob.dec.wsgify()
def __call__(self, req):
if req.content_length > CONF.max_request_body_size:
if req.content_length is None:
if req.is_body_readable:
limiter = utils.LimitingReader(req.body_file,
CONF.max_request_body_size)
req.body_file = limiter
elif req.content_length > CONF.max_request_body_size:
raise exception.RequestTooLarge()
if req.content_length is None and req.is_body_readable:
limiter = utils.LimitingReader(req.body_file,
CONF.max_request_body_size)
req.body_file = limiter
return self.application

View File

@ -38,19 +38,19 @@ class TestRequestBodySizeLimiter(tests.TestCase):
def test_content_length_acceptable(self):
self.request.headers['Content-Length'] = MAX_REQUEST_BODY_SIZE
self.request.body = "0" * MAX_REQUEST_BODY_SIZE
self.request.body = b"0" * MAX_REQUEST_BODY_SIZE
response = self.request.get_response(self.middleware)
self.assertEqual(200, response.status_int)
def test_content_length_too_large(self):
self.request.headers['Content-Length'] = MAX_REQUEST_BODY_SIZE + 1
self.request.body = "0" * (MAX_REQUEST_BODY_SIZE + 1)
self.request.body = b"0" * (MAX_REQUEST_BODY_SIZE + 1)
self.assertRaises(exception.RequestTooLarge,
self.request.get_response,
self.middleware)
def test_request_too_large_no_content_length(self):
self.request.body = "0" * (MAX_REQUEST_BODY_SIZE + 1)
self.request.body = b"0" * (MAX_REQUEST_BODY_SIZE + 1)
self.request.headers['Content-Length'] = None
self.assertRaises(exception.RequestTooLarge,
self.request.get_response,

View File

@ -21,6 +21,7 @@ commands =
keystone/tests/test_cache_backend_mongo.py \
keystone/tests/test_injection.py \
keystone/tests/test_singular_plural.py \
keystone/tests/test_sizelimit.py \
keystone/tests/unit
[testenv:pep8]