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