Skip to content
This repository
tag: v1.0.3
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 47 lines (34 sloc) 1.618 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
import tornado.ioloop
import time
import logging

import test_shunt
import asyncmongo

TEST_TIMESTAMP = int(time.time())

class InsertDeleteTest(test_shunt.MongoTest):
    def test_insert(self):
        test_shunt.setup()
        db = asyncmongo.Client(pool_id='testinsert', host='127.0.0.1', port=27017, dbname='test')
        
        def insert_callback(response, error):
            logging.info(response)
            assert len(response) == 1
            test_shunt.register_called('inserted')
            tornado.ioloop.IOLoop.instance().stop()
        
        db.test_users.insert({"_id" : "insert.%d" % TEST_TIMESTAMP}, callback=insert_callback)
        
        tornado.ioloop.IOLoop.instance().start()
        test_shunt.assert_called('inserted')
        
        def query_callback(response, error):
            logging.info(response)
            assert len(response) == 1
            test_shunt.register_called('retrieved')
            tornado.ioloop.IOLoop.instance().stop()
        
        db.test_users.find_one({"_id" : "insert.%d" % TEST_TIMESTAMP}, callback=query_callback)
        tornado.ioloop.IOLoop.instance().start()
        test_shunt.assert_called('retrieved')

        
        def delete_callback(response, error):
            logging.info(response)
            assert len(response) == 1
            test_shunt.register_called('deleted')
            tornado.ioloop.IOLoop.instance().stop()
        
        db.test_users.remove({"_id" : "insert.%d" % TEST_TIMESTAMP}, callback=delete_callback)
        tornado.ioloop.IOLoop.instance().start()
        test_shunt.assert_called('deleted')

Something went wrong with that request. Please try again.