response = self.fetch('/', method='OTHER',
allow_nonstandard_methods=True)
self.assertEqual(response.body, b'other')
+
+
+@wsgi_safe
+class FinishInPrepareTest(SimpleHandlerTestCase):
+ class Handler(RequestHandler):
+ def prepare(self):
+ self.finish('done')
+
+ def get(self):
+ # It's difficult to assert for certain that a method did not
+ # or will not be called in an asynchronous context, but this
+ # will be logged noisily if it is reached.
+ raise Exception('should not reach this method')
+
+ def test_finish_in_prepare(self):
+ response = self.fetch('/')
+ self.assertEqual(response.body, b'done')
self._handle_request_exception(e)
def _execute_method(self):
- method = getattr(self, self.request.method.lower())
- self._when_complete(method(*self.path_args, **self.path_kwargs),
- self._execute_finish)
+ if not self._finished:
+ method = getattr(self, self.request.method.lower())
+ self._when_complete(method(*self.path_args, **self.path_kwargs),
+ self._execute_finish)
def _execute_finish(self):
if self._auto_finish and not self._finished: