Skip to content
This repository has been archived by the owner on May 31, 2019. It is now read-only.

Commit

Permalink
Modify after request hook
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bata committed Dec 18, 2016
1 parent 5ca7fa3 commit 9d69d85
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
4 changes: 3 additions & 1 deletion kobin/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ def _handle(self, environ):
response = callback(**kwargs) if kwargs else callback()

if self.after_request_callback:
response = self.after_request_callback(response)
wrapped_response = self.after_request_callback(response)
if wrapped_response:
response = wrapped_response
except HTTPError as e:
response = e
except BaseException as e:
Expand Down
20 changes: 20 additions & 0 deletions tests/test_apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,26 @@ def test_after_request(self):
self.assertIn(('Foo', 'Bar'), response.headerlist)


class KobinAfterHookTests(TestCase):
def setUp(self):
self.app = Kobin()
self.dummy_start_response = lambda x, y: None
self.before_counter = 0

@self.app.route('/')
def dummy_func():
return Response('hello')

@self.app.after_request
def after_do_not_return_response(response):
pass

def test_after_request(self):
test_env = {'REQUEST_METHOD': 'GET', 'PATH_INFO': '/'}
response = self.app._handle(test_env)
self.assertEqual('200 OK', response.status)


class ConfigTests(TestCase):
def setUp(self):
self.root_path = os.path.dirname(os.path.abspath(__file__))
Expand Down

0 comments on commit 9d69d85

Please sign in to comment.