diff --git a/falcon/responders.py b/falcon/responders.py index ebc7571..d1deea4 100644 --- a/falcon/responders.py +++ b/falcon/responders.py @@ -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)) diff --git a/tests/test_http_method_routing.py b/tests/test_http_method_routing.py index 92945f4..6001277 100644 --- a/tests/test_http_method_routing.py +++ b/tests/test_http_method_routing.py @@ -60,6 +60,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(testing.TestSuite): def prepare(self): @@ -69,6 +78,10 @@ class TestHttpMethodRouting(testing.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) @@ -96,6 +109,23 @@ class TestHttpMethodRouting(testing.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)