Merge pull request #72 from painterjd/method_not_allowed_with_param

fix($routing): Fix endpoint routing w/ params
This commit is contained in:
Kurt Griffiths
2013-02-07 09:15:23 -08:00
2 changed files with 31 additions and 1 deletions

View File

@@ -43,7 +43,7 @@ def create_method_not_allowed(allowed_methods):
"""
def method_not_allowed(req, resp):
def method_not_allowed(req, resp, **params):
resp.status = HTTP_405
resp.set_header('Allow', ', '.join(allowed_methods))

View File

@@ -61,6 +61,15 @@ class ResourceMisc(object):
pass
class ResourceGetWithParam(object):
def __init__(self):
self.called = False
@capture
def on_get(self, req, resp):
resp.status = falcon.HTTP_204
class TestHttpMethodRouting(helpers.TestSuite):
def prepare(self):
@@ -70,6 +79,10 @@ class TestHttpMethodRouting(helpers.TestSuite):
self.resource_misc = ResourceMisc()
self.api.add_route('/misc', self.resource_misc)
self.resource_get_with_param = ResourceGetWithParam()
self.api.add_route('/get_with_param/{param}',
self.resource_get_with_param)
def test_get(self):
self._simulate_request('/get')
self.assertTrue(self.resource_get.called)
@@ -97,6 +110,23 @@ class TestHttpMethodRouting(helpers.TestSuite):
self.assertThat(headers, Contains(allow_header))
def test_method_not_allowed_with_param(self):
for method in HTTP_METHODS:
if method == 'GET':
continue
self.resource_get_with_param.called = False
self._simulate_request(
'/get_with_param/bogus_param', method=method)
self.assertFalse(self.resource_get_with_param.called)
self.assertEquals(self.srmock.status, '405 Method Not Allowed')
headers = self.srmock.headers
allow_header = ('Allow', 'GET')
self.assertThat(headers, Contains(allow_header))
def test_bogus_method(self):
self._simulate_request('/get', method=self.getUniqueString())
self.assertFalse(self.resource_get.called)