Q: How to test session based scenarios (login, logout, @ authenticated )?
A: need to handle Cookie: parse set-Cookie response headers and provide cookie request headers.
Https://gist.github.com/wolf0403/5488165
Q: Motor (async Mongo client) timeouts in asynchttptestcase?
A: By default, test cases runs in separate ioloops. This prevents motor from faster Ming correctly. Fix:
Http://stackoverflow.com/questions/14688042/tornado-blocked-while-testing-asynchronous-method-using-asynchttptastcase
Q: How to Do user login?
A: return something inside get_current_user. This comes from Cookie (which forms "session ").
class AuthMixin(object):COOKIE_USER = 'user'def set_user(self, u): # django: login(), not auth()self.set_secure_cookie(self.COOKIE_USER, u)def get_user(self):return self.get_secure_cookie(self.COOKIE_USER)def clear_user(self):self.clear_cookie(self.COOKIE_USER)class ResourceHandler(tornado.web.RequestHandler, AuthMixin):def get_current_user(self):return self.get_user()
Q: set_header (K, V); get_header (k )! = V, why?
A: get_header always retrieves cookies from the request, while set_cookie sets to the response. Only way to verify is to check cookies brought back by the next request.