Reputation: 1388
I have a handler (subclass of RequestHandler) which handles GET, POST, PUT and DELETE requests. The class also has independent functions which operates on DB. I am writing unit test for the class, but I am not able to initialize the class since it requires 2 arguments. How can I do it?
Note: I don't have issues while testing rest calls.
Upvotes: 1
Views: 337
Reputation: 1388
I solved the issue by making my testcase class a subclass of the class under testing.
Upvotes: 1
Reputation: 22134
The two arguments are the tornado.web.Application
and the tornado.httputil.HTTPServerRequest
. Normally, rather than constructing a RequestHandler
directly, Tornado applications are tested via tornado.testing.AsyncHTTPTestCase
which will create the handlers as needed. (You could construct the application
and request
by hand, but I wouldn't recommend it)
Do the functions you want to test need the application
or request
objects? If not, you could move them out of the subclass of RequestHandler
to test them in isolation. If they do need either of these objects, then AsyncHTTPTestCase
is the simplest way to get them.
Upvotes: 0