diff options
author | W. Trevor King <wking@tremily.us> | 2012-08-24 10:08:33 -0400 |
---|---|---|
committer | W. Trevor King <wking@tremily.us> | 2012-08-24 10:08:33 -0400 |
commit | cdc8049dd294d046813b18c759ee7f16ccf08746 (patch) | |
tree | 6bb9bfe27322e465d81c262c380263d5b5ce0ca6 /libbe | |
parent | 09a28055449f3b574710dfce9fb4524cd770e381 (diff) | |
download | bugseverywhere-cdc8049dd294d046813b18c759ee7f16ccf08746.tar.gz |
command:serve: add ability to pass raw POST data with getURL.
This is analagous to the earlier change to get_post_url:
commit 0cd072b9710ee964e6f449abd9265d85e02f34d2
Author: W. Trevor King <wking@tremily.us>
Date: Fri Aug 24 09:29:58 2012 -0400
util:http: add ability to pass raw POST data with get_post_url.
Diffstat (limited to 'libbe')
-rw-r--r-- | libbe/command/serve.py | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/libbe/command/serve.py b/libbe/command/serve.py index 1206ebd..4057536 100644 --- a/libbe/command/serve.py +++ b/libbe/command/serve.py @@ -937,19 +937,23 @@ if libbe.TESTING == True: 'wsgi.run_once':False, } def getURL(self, app, path='/', method='GET', data=None, - scheme='http', environ={}): + data_dict=None, scheme='http', environ={}): env = copy.copy(self.default_environ) env['PATH_INFO'] = path env['REQUEST_METHOD'] = method env['scheme'] = scheme - if data != None: - enc_data = urllib.urlencode(data) + if data_dict is not None: + assert data is None, (data, data_dict) + data = urllib.urlencode(data_dict) + if data is not None: + if data_dict is None: + assert method == 'POST', (method, data) if method == 'POST': - env['CONTENT_LENGTH'] = len(enc_data) - env['wsgi.input'] = StringIO.StringIO(enc_data) + env['CONTENT_LENGTH'] = len(data) + env['wsgi.input'] = StringIO.StringIO(data) else: assert method in ['GET', 'HEAD'], method - env['QUERY_STRING'] = enc_data + env['QUERY_STRING'] = data for key,value in environ.items(): env[key] = value return ''.join(app(env, self.start_response)) @@ -1021,7 +1025,7 @@ if libbe.TESTING == True: def test_new_name(self): self.getURL( self.app, '/admin/', method='POST', - data={'name':'Prince Al'}, + data_dict={'name':'Prince Al'}, environ={'HTTP_Authorization': self.basic_auth('Aladdin', 'open sesame')}) self.failUnless(self.status == '200 OK', self.status) @@ -1035,7 +1039,7 @@ if libbe.TESTING == True: def test_new_password(self): self.getURL( self.app, '/admin/', method='POST', - data={'password':'New Pass'}, + data_dict={'password':'New Pass'}, environ={'HTTP_Authorization': self.basic_auth('Aladdin', 'open sesame')}) self.failUnless(self.status == '200 OK', self.status) @@ -1050,7 +1054,7 @@ if libbe.TESTING == True: def test_guest_name(self): self.getURL( self.app, '/admin/', method='POST', - data={'name':'SPAM'}, + data_dict={'name':'SPAM'}, environ={'HTTP_Authorization': self.basic_auth('guest', 'guestpass')}) self.failUnless(self.status.startswith('403 '), self.status) @@ -1065,7 +1069,7 @@ if libbe.TESTING == True: def test_guest_password(self): self.getURL( self.app, '/admin/', method='POST', - data={'password':'SPAM'}, + data_dict={'password':'SPAM'}, environ={'HTTP_Authorization': self.basic_auth('guest', 'guestpass')}) self.failUnless(self.status.startswith('403 '), self.status) @@ -1095,8 +1099,8 @@ if libbe.TESTING == True: self.failUnless(self.exc_info == None, self.exc_info) def test_add_post(self): self.getURL(self.app, '/add/', method='POST', - data={'id':'123456', 'parent':'abc123', - 'directory':'True'}) + data_dict={'id':'123456', 'parent':'abc123', + 'directory':'True'}) self.failUnless(self.status == '200 OK', self.status) self.failUnless(self.response_headers == [], self.response_headers) |