Skip to content

Commit

Permalink
Fix #1416
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov committed Dec 7, 2016
1 parent 36b1432 commit fdba13d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
9 changes: 7 additions & 2 deletions aiohttp/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ class AbstractRouter(ABC):
def __init__(self):
self._frozen = False

@abstractmethod
def post_init(self, app):
pass # pragma: no cover
"""Post init stage.
It's not an abstract method for sake of backward compatibility
but if router wans to be aware about application it should
override it.
"""

@property
def frozen(self):
Expand Down
5 changes: 4 additions & 1 deletion aiohttp/web_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,10 @@ def app(self):

@asyncio.coroutine
def _prepare_hook(self, response):
for app in self.match_info.apps:
match_info = self._match_info
if match_info is None:
return
for app in match_info.apps:
yield from app.on_response_prepare.send(self, response)


Expand Down
20 changes: 19 additions & 1 deletion tests/test_web_urldispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import pytest

from aiohttp import web
from aiohttp import abc, web
from aiohttp.web_urldispatcher import SystemRoute


Expand Down Expand Up @@ -270,3 +270,21 @@ def test_system_route():
assert "<SystemRoute 201: test>" == repr(route)
assert 201 == route.status
assert 'test' == route.reason


@asyncio.coroutine
def test_412_is_returned(loop, test_client):

class MyRouter(abc.AbstractRouter):

@asyncio.coroutine
def resolve(self, request):
raise web.HTTPPreconditionFailed()

app = web.Application(router=MyRouter(), loop=loop)

client = yield from test_client(app)

resp = yield from client.get('/')

assert resp.status == 412

0 comments on commit fdba13d

Please sign in to comment.