Skip to content

Commit

Permalink
Add support for PUT and PATCH in prequest (Pylons#877)
Browse files Browse the repository at this point in the history
  • Loading branch information
merwok committed Jun 19, 2013
1 parent cb8bb94 commit cd9d7f5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pyramid/scripts/prequest.py
Expand Up @@ -59,9 +59,9 @@ class PRequestCommand(object):
parser.add_option(
'-m', '--method',
dest='method',
choices=['GET', 'HEAD', 'POST', 'DELETE'],
choices=['GET', 'HEAD', 'POST', 'PUT', 'PATCH', 'DELETE'],
type='choice',
help='Request method type (GET, POST, DELETE)',
help='Request method type',
)

get_app = staticmethod(get_app)
Expand Down Expand Up @@ -127,7 +127,7 @@ def run(self):
'paste.command_request': True,
}

if request_method == 'POST':
if request_method in ('POST', 'PUT', 'PATCH'):
environ['wsgi.input'] = self.stdin
environ['CONTENT_LENGTH'] = '-1'

Expand Down
26 changes: 26 additions & 0 deletions pyramid/tests/test_scripts/test_prequest.py
Expand Up @@ -114,6 +114,32 @@ def test_command_method_post(self):
self.assertEqual(self._app_name, None)
self.assertEqual(self._out, ['abc'])

def test_command_method_put(self):
from pyramid.compat import NativeIO
command = self._makeOne(['', '--method=PUT', 'development.ini', '/'])
stdin = NativeIO()
command.stdin = stdin
command.run()
self.assertEqual(self._environ['CONTENT_LENGTH'], '-1')
self.assertEqual(self._environ['wsgi.input'], stdin)
self.assertEqual(self._path_info, '/')
self.assertEqual(self._spec, 'development.ini')
self.assertEqual(self._app_name, None)
self.assertEqual(self._out, ['abc'])

def test_command_method_patch(self):
from pyramid.compat import NativeIO
command = self._makeOne(['', '--method=PATCH', 'development.ini', '/'])
stdin = NativeIO()
command.stdin = stdin
command.run()
self.assertEqual(self._environ['CONTENT_LENGTH'], '-1')
self.assertEqual(self._environ['wsgi.input'], stdin)
self.assertEqual(self._path_info, '/')
self.assertEqual(self._spec, 'development.ini')
self.assertEqual(self._app_name, None)
self.assertEqual(self._out, ['abc'])

def test_command_with_query_string(self):
command = self._makeOne(['', 'development.ini', '/abc?a=1&b=2&c'])
command.run()
Expand Down

0 comments on commit cd9d7f5

Please sign in to comment.