I’m building a simple web application in tornado.web using mongodb as the backend. 90% of the server-side codebase lives in a set of RequestHandlers, and 90% of the data objects are json. As a result, the basic use case for testing handlers is:
"Given Request Y and DB in state X,
verify that handler method Z returns json object J"
How do I set up this kind of test?
I’ve found a few blog posts and discussion threads on the topic, but they mainly focus on setting up asyncronous. I can’t find anything on setting up the right kind of DB state or GET/POST request arguments.
I would typically mock out the inputs and just test the output. This is a contrived example using this mocking library – http://www.voidspace.org.uk/python/mock/. You would have to mock out the correct mongodb query function. I’m not sure what you are using.