Call torando Request Handler function without running tornado loop start?

787 views Asked by At

I need to store the output of a get function of a request handler before running the tornado server from outside the application.

Example:-

class Test(RequestHandler):

  def get:
       print "safds"'

   ....
   ...

I need to call get function without tornado loop server from outside. Is it possible ? Is there any turnaround. Please help.

Thanks

1

There are 1 answers

0
nima On

If you happen to end up reading this question, I knew that I had to somehow create an instance of my handler to be able to call the post or get function inside. After looking at the RequestHandler's implementation, I came up with the following snippet:

from tornado.web import Application
from tornado.httpserver import HTTPRequest

mock_app = Mock(spec=Application)
request = HTTPRequest(
        method='GET', uri='/', headers=None, body=None
)
response = Handler(mock_app, request).get()