Tornado asynchttptestcase gotchas

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.