

def test_find_and_modify(self):
    db = asyncmongo.Client(pool_id='test_query', host='127.0.0.1', port=int(self.mongod_options[0][1]), dbname='test', mincached=3)
    results = []

    def callback(response, error):
        tornado.ioloop.IOLoop.instance().stop()
        self.assert_((error is None))
        results.append(response['value'])
    before = self.get_open_cursors()
    db.command('findAndModify', 'foo', callback=callback, query={
        '_id': 2,
    }, update={
        '$set': {
            's': 'a',
        },
    }, upsert=True, new=True)
    tornado.ioloop.IOLoop.instance().start()
    self.assertEqual({
        '_id': 2,
        's': 'a',
    }, results[0])
    db.command('findAndModify', 'foo', callback=callback, query={
        '_id': 2,
    }, update={
        '$set': {
            's': 'b',
        },
    }, upsert=True, new=True)
    tornado.ioloop.IOLoop.instance().start()
    self.assertEqual({
        '_id': 2,
        's': 'b',
    }, results[1])
    after = self.get_open_cursors()
    assert (before == after), ('%d cursors left open (should be 0)' % (after - before))

dataset/ETHPy150Open bitly/asyncmongo/test/test_command.py CommandTest.test_find_and_modify/original