Skip to content

Commit

Permalink
Add support for DELETE and PATCH methods in local mode
Browse files Browse the repository at this point in the history
Fixes aws#167.
  • Loading branch information
jamesls committed Nov 15, 2016
1 parent e313ccc commit 34d1c88
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion chalice/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ def _generate_lambda_event(self):
)
return lambda_event

do_GET = do_PUT = do_POST = do_HEAD = _generic_handle
do_GET = do_PUT = do_POST = do_HEAD = do_DELETE = do_PATCH = \
_generic_handle

def do_OPTIONS(self):
# This can either be because the user's provided an OPTIONS method
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def cors():
def options():
return {'options': True}

@demo.route('/delete', methods=['DELETE'])
def delete():
return {'delete': True}

@demo.route('/patch', methods=['PATCH'])
def patch():
return {'patch': True}

@demo.route('/badrequest')
def badrequest():
raise BadRequestError('bad-request')
Expand Down Expand Up @@ -140,6 +148,24 @@ def test_errors_converted_to_json_response(handler):
'Message': 'BadRequestError: bad-request'}


def test_can_support_delete_method(handler):
handler.command = 'DELETE'
handler.path = '/delete'
handler.headers = {'content-type': 'application/json'}
handler.do_DELETE()
body = _get_body_from_response_stream(handler)
assert body == {'delete': True}


def test_can_support_patch_method(handler):
handler.command = 'PATCH'
handler.path = '/patch'
handler.headers = {'content-type': 'application/json'}
handler.do_PATCH()
body = _get_body_from_response_stream(handler)
assert body == {'patch': True}


def test_unsupported_methods_raise_error(handler):
handler.command = 'POST'
handler.path = '/index'
Expand Down

0 comments on commit 34d1c88

Please sign in to comment.