Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ResourceAdapter: dont add method to allowed if resource is not match #826

Merged
merged 1 commit into from
Mar 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions aiohttp/web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion tests/test_urldispatch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')))

Expand Down Expand Up @@ -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)