Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8118735
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T04:35:17+00:00 2026-06-06T04:35:17+00:00

I’m building a simple web application in tornado.web using mongodb as the backend. 90%

  • 0

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.

  • http://emptysquare.net/blog/tornado-unittesting-eventually-correct/
  • http://www.tornadoweb.org/documentation/testing.html
  • https://groups.google.com/group/python-tornado/browse_thread/thread/867cfb2665ea10a9/319555e619fe6c5c
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T04:35:20+00:00Added an answer on June 6, 2026 at 4:35 am

    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.

    from mock import Mock, patch
    import json
    
    
    @patch('my_tornado_server.mongo_db_connection.query')
    def test_a_random_handler_returns_some_json(self, mock_mongo_query):
    
        request = Mock()
        # Set any other attributes on the request that you need
        mock_mongo_query.return_value = ['pink', 'orange', 'purple']
    
        application = Mock()
        handler = RandomHandler(application, request)
        handler.write = Mock()
    
        handler.get('some_arg')
    
        self.assertEqual(handler.write.call_args_list, json.dumps({'some': 'data'}))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
We're building an app, our first using Rails 3, and we're having to build
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.