Created
January 15, 2013 18:17
-
-
Save robert-zaremba/4540679 to your computer and use it in GitHub Desktop.
This application presents mongotor bug
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tornado.web | |
from tornado import gen | |
from mongotor.database import Database | |
from bson import ObjectId | |
class Handler(tornado.web.RequestHandler): | |
def initialize(self): | |
self.db = Database.connect('localhost:27017', 'regisys') | |
@tornado.web.asynchronous | |
@gen.engine | |
def get(self): | |
user = {'_id': ObjectId(), 'name': 'User Name'} | |
yield gen.Task(self.db.user.insert, user) | |
yield gen.Task(self.db.user.update, user['_id'], | |
{"$set": {'name': 'New User Name'}}) | |
user_found = yield gen.Task(self.db.user.find_one, user['_id']) | |
assert user_found['name'] == 'New User Name' | |
yield gen.Task(self.db.user.remove, user['_id']) | |
import tornado.ioloop | |
application = tornado.web.Application([ | |
(r"/", Handler), | |
]) | |
if __name__ == "__main__": | |
application.listen(8000) | |
tornado.ioloop.IOLoop.instance().start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment