diff --git a/aiohttp/web_urldispatcher.py b/aiohttp/web_urldispatcher.py index e9e57ed9ff5..307b84b5979 100644 --- a/aiohttp/web_urldispatcher.py +++ b/aiohttp/web_urldispatcher.py @@ -204,10 +204,11 @@ def url(self, **kwargs): @asyncio.coroutine def resolve(self, method, path): route_method = self._route.method - allowed_methods = {route_method} - if route_method == method or route_method == hdrs.METH_ANY: - match_dict = self._route.match(path) - if match_dict is not None: + allowed_methods = set() + match_dict = self._route.match(path) + if match_dict is not None: + allowed_methods.add(route_method) + if route_method == hdrs.METH_ANY or route_method == method: return (UrlMappingMatchInfo(match_dict, self._route), allowed_methods) return None, allowed_methods diff --git a/tests/test_urldispatch.py b/tests/test_urldispatch.py index 427646a5410..9c718aadf49 100644 --- a/tests/test_urldispatch.py +++ b/tests/test_urldispatch.py @@ -697,7 +697,7 @@ def test_resource_adapter_resolve_not_math(self): route = PlainRoute('GET', lambda req: None, None, '/path') self.router.register_route(route) resource = route.resource - self.assertEqual((None, {'GET'}), + self.assertEqual((None, set()), self.loop.run_until_complete( resource.resolve('GET', '/another/path'))) @@ -888,3 +888,19 @@ def test_static_route_points_to_file(self): here = pathlib.Path(aiohttp.__file__).parent / '__init__.py' with self.assertRaises(ValueError): self.router.add_static('/st', here) + + def test_404_for_resource_adapter(self): + route = self.router.add_static('/st', + os.path.dirname(aiohttp.__file__)) + resource = route.resource + ret = self.loop.run_until_complete( + resource.resolve('GET', '/unknown/path')) + self.assertEqual((None, set()), ret) + + def test_405_for_resource_adapter(self): + route = self.router.add_static('/st', + os.path.dirname(aiohttp.__file__)) + resource = route.resource + ret = self.loop.run_until_complete( + resource.resolve('POST', '/st/abc.py')) + self.assertEqual((None, {'GET'}), ret)