fix swob for make_pre_authed_request
Change-Id: Ic263f4a77a0aa0eb40078772a567eb41a60e40f7
This commit is contained in:
parent
6801920785
commit
7f476d7b48
@ -639,15 +639,16 @@ class Request(object):
|
||||
'SERVER_PROTOCOL': 'HTTP/1.0',
|
||||
'wsgi.version': (1, 0),
|
||||
'wsgi.url_scheme': 'http',
|
||||
'wsgi.input': StringIO(body or ''),
|
||||
'wsgi.errors': StringIO(''),
|
||||
'wsgi.multithread': False,
|
||||
'wsgi.multiprocess': False
|
||||
}
|
||||
env.update(PATH_INFO=path_info)
|
||||
env.update(environ)
|
||||
if body is not None:
|
||||
env.update(CONTENT_LENGTH=str(len(body)))
|
||||
env['wsgi.input'] = StringIO(body)
|
||||
env['CONTENT_LENGTH'] = str(len(body))
|
||||
elif 'wsgi.input' not in env:
|
||||
env['wsgi.input'] = StringIO('')
|
||||
req = Request(env)
|
||||
for key, val in headers.iteritems():
|
||||
req.headers[key] = val
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
import unittest
|
||||
import datetime
|
||||
from StringIO import StringIO
|
||||
|
||||
import swift.common.swob
|
||||
|
||||
@ -195,6 +196,16 @@ class TestRequest(unittest.TestCase):
|
||||
self.assertEquals(req.headers['Content-Type'], 'text/plain')
|
||||
self.assertEquals(req.method, 'POST')
|
||||
|
||||
def test_blank_body_precedence(self):
|
||||
req = swift.common.swob.Request.blank(
|
||||
'/', environ={'REQUEST_METHOD': 'POST',
|
||||
'wsgi.input': StringIO('')},
|
||||
headers={'Content-Type': 'text/plain'}, body='hi')
|
||||
self.assertEquals(req.path_info, '/')
|
||||
self.assertEquals(req.body, 'hi')
|
||||
self.assertEquals(req.headers['Content-Type'], 'text/plain')
|
||||
self.assertEquals(req.method, 'POST')
|
||||
|
||||
def test_params(self):
|
||||
req = swift.common.swob.Request.blank('/?a=b&c=d')
|
||||
self.assertEquals(req.params['a'], 'b')
|
||||
@ -218,8 +229,8 @@ class TestRequest(unittest.TestCase):
|
||||
self.assertEquals(req.path_info_pop(), None)
|
||||
|
||||
def test_copy_get(self):
|
||||
req = swift.common.swob.Request.blank('/hi/there',
|
||||
environ={'REQUEST_METHOD': 'POST'})
|
||||
req = swift.common.swob.Request.blank(
|
||||
'/hi/there', environ={'REQUEST_METHOD': 'POST'})
|
||||
self.assertEquals(req.method, 'POST')
|
||||
req2 = req.copy_get()
|
||||
self.assertEquals(req2.method, 'GET')
|
||||
|
@ -33,6 +33,7 @@ from eventlet import sleep
|
||||
from swift.common.swob import Request
|
||||
from swift.common import wsgi
|
||||
|
||||
|
||||
class TestWSGI(unittest.TestCase):
|
||||
""" Tests for swift.common.wsgi """
|
||||
|
||||
@ -217,6 +218,10 @@ class TestWSGI(unittest.TestCase):
|
||||
{'QUERY_STRING': 'original'}, 'GET', 'path?')
|
||||
self.assertEquals(r.query_string, '')
|
||||
|
||||
def test_pre_auth_req_with_body(self):
|
||||
r = wsgi.make_pre_authed_request(
|
||||
{'QUERY_STRING': 'original'}, 'GET', 'path', 'the body')
|
||||
self.assertEquals(r.body, 'the body')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
Loading…
Reference in New Issue
Block a user