From 5015965c733227c6698dac8bb9f287a2e506110e Mon Sep 17 00:00:00 2001 From: Bernardo Heynemann Date: Wed, 21 May 2014 18:32:11 -0300 Subject: [PATCH] Updating to newer versions of motor and pymongo --- benchmark/base.py | 6 +++--- benchmark/server.py | 4 ++-- docs/source/connecting.rst | 10 +++++----- docs/source/getting-started.rst | 20 +++++++++++-------- docs/source/modeling.rst | 4 ++-- docs/source/saving.rst | 6 +++--- motorengine/document.py | 2 +- motorengine/query_builder/node.py | 2 +- motorengine/queryset.py | 4 ++-- setup.py | 2 +- tests/__init__.py | 2 +- tests/integration/base.py | 4 ++-- tests/integration/fields/test_binary_field.py | 3 +-- tests/test_connect.py | 6 +++--- tests/test_database.py | 4 ++-- tests/test_document.py | 2 +- 16 files changed, 42 insertions(+), 39 deletions(-) diff --git a/benchmark/base.py b/benchmark/base.py index 53d10af..1cd4669 100644 --- a/benchmark/base.py +++ b/benchmark/base.py @@ -11,9 +11,9 @@ class BenchmarkTest(AsyncHTTPTestCase, LogTrapTestCase): def setUp(self): super(BenchmarkTest, self).setUp() - self.db = motorengine.connect("test", host="localhost", port=4445, io_loop=self.io_loop) - mongoengine.connect("test", host="localhost", port=4445) - self.motor = motor.MotorClient('localhost', 4445, io_loop=self.io_loop, max_concurrent=500).open_sync() + self.db = motorengine.connect("test", host="localhost", port=27017, io_loop=self.io_loop) + mongoengine.connect("test", host="localhost", port=27017) + self.motor = motor.MotorClient('localhost', 27017, io_loop=self.io_loop, max_concurrent=500).open_sync() def tearDown(self): motorengine.connection.cleanup() diff --git a/benchmark/server.py b/benchmark/server.py index 8df2f92..0d4b4dc 100644 --- a/benchmark/server.py +++ b/benchmark/server.py @@ -55,7 +55,7 @@ def get_app(): application.listen(8888) io_loop = tornado.ioloop.IOLoop.instance() - motorengine.connect("test", host="localhost", port=4445, io_loop=io_loop) - mongoengine.connect("test", host="localhost", port=4445) + motorengine.connect("test", host="localhost", port=27017, io_loop=io_loop) + mongoengine.connect("test", host="localhost", port=27017) io_loop.start() diff --git a/docs/source/connecting.rst b/docs/source/connecting.rst index f80f96e..fee47e7 100644 --- a/docs/source/connecting.rst +++ b/docs/source/connecting.rst @@ -8,7 +8,7 @@ Simple Connection MotorEngine supports connecting to the database using a myriad of options via the `connect` method. -.. autofunction:: motorengine.connection.connect(db, host="localhost", port=4445, io_loop=io_loop) +.. autofunction:: motorengine.connection.connect(db, host="localhost", port=27017, io_loop=io_loop) :noindex: .. testsetup:: connecting_connecting @@ -24,7 +24,7 @@ MotorEngine supports connecting to the database using a myriad of options via th io_loop = tornado.ioloop.IOLoop.instance() # you only need to keep track of the DB instance if you connect to multiple databases. - connect("connecting-test", host="localhost", port=4445, io_loop=io_loop) + connect("connecting-test", host="localhost", port=27017, io_loop=io_loop) Replica Sets ------------ @@ -52,7 +52,7 @@ You also need to specify the name of the Replica Set in the `replicaSet` paramet Multiple Databases ------------------ -.. autofunction:: motorengine.connection.connect(db, alias="db1", host="localhost", port=4445, io_loop=io_loop) +.. autofunction:: motorengine.connection.connect(db, alias="db1", host="localhost", port=27017, io_loop=io_loop) :noindex: Connecting to multiple databases is as simple as specifying a different alias to each connection. @@ -77,8 +77,8 @@ Let's say you need to connect to an users and a posts databases: io_loop = tornado.ioloop.IOLoop.instance() - connect("posts", host="localhost", port=4445, io_loop=io_loop) # the posts database is the default - connect("users", alias="users", host="localhost", port=4445, io_loop=io_loop) # the users database uses an alias + connect("posts", host="localhost", port=27017, io_loop=io_loop) # the posts database is the default + connect("users", alias="users", host="localhost", port=27017, io_loop=io_loop) # the users database uses an alias # now when querying for users we'll just specify the alias we want to use User.objects.find_all(alias="users") diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst index 86dc414..f4f9ed7 100644 --- a/docs/source/getting-started.rst +++ b/docs/source/getting-started.rst @@ -27,7 +27,7 @@ Connecting to a Database # instantiate tornado server and apps so we get io_loop instance io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) # you only need to keep track of the + connect("test", host="localhost", port=27017, io_loop=io_loop) # you only need to keep track of the # DB instance if you connect to multiple databases. Modeling a Document @@ -70,7 +70,7 @@ Due to the asynchronous nature of MotorEngine, you are required to handle saving employee_id = IntField(required=True) io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: creating_new_instance @@ -109,7 +109,7 @@ Updating an instance is as easy as changing a property and calling save again: employee_id = IntField(required=True) io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: updating_instance @@ -152,7 +152,7 @@ To get an object by id, you must specify the ObjectId that the instance got crea employee_id = IntField(required=True) io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: getting_instance @@ -209,11 +209,15 @@ All of these options can be combined to really tune how to get items: employee_id = IntField(required=True) io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: filtering_instances - def get_employees(): + def create_employee(): + emp = Employee(first_name="Bernardo", last_name="Heynemann", employee_id=1538) + emp.save(handle_employee_saved) + + def handle_employee_saved(emp): # return the first 10 employees ordered by last_name that joined after 2010 Employee.objects \ .limit(10) \ @@ -228,7 +232,7 @@ All of these options can be combined to really tune how to get items: finally: io_loop.stop() - io_loop.add_timeout(1, get_employees) + io_loop.add_timeout(1, create_employee) io_loop.start() Counting documents in collections @@ -250,7 +254,7 @@ Counting documents in collections employee_id = IntField(required=True) io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: counting_instances diff --git a/docs/source/modeling.rst b/docs/source/modeling.rst index 2263196..643a771 100644 --- a/docs/source/modeling.rst +++ b/docs/source/modeling.rst @@ -32,7 +32,7 @@ Let's say we need an article model with title, description and published_date: io_loop = tornado.ioloop.IOLoop.instance() # you only need to keep track of the DB instance if you connect to multiple databases. - connect("connecting-test", host="localhost", port=4445, io_loop=io_loop) + connect("connecting-test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: modeling_1 @@ -54,7 +54,7 @@ That allows us to create, update, query and remove articles with extreme ease: io_loop = tornado.ioloop.IOLoop.instance() # you only need to keep track of the DB instance if you connect to multiple databases. - connect("connecting-test", host="localhost", port=4445, io_loop=io_loop) + connect("connecting-test", host="localhost", port=27017, io_loop=io_loop) class Article(Document): __collection__ = "ModelingArticles2" diff --git a/docs/source/saving.rst b/docs/source/saving.rst index 0948437..552d4f9 100644 --- a/docs/source/saving.rst +++ b/docs/source/saving.rst @@ -20,7 +20,7 @@ The easiest way of creating a new instance of a document is using `Document.obje name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_save @@ -54,7 +54,7 @@ To update an instance, just make the needed changes to an instance and then call name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_update @@ -103,7 +103,7 @@ MotorEngine supports bulk insertion of documents by calling the `bulk_insert` me name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_bulk diff --git a/motorengine/document.py b/motorengine/document.py index b0089ea..ea7905d 100644 --- a/motorengine/document.py +++ b/motorengine/document.py @@ -108,7 +108,7 @@ class User(Document): name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_delete_one diff --git a/motorengine/query_builder/node.py b/motorengine/query_builder/node.py index 694ce85..75d0d53 100644 --- a/motorengine/query_builder/node.py +++ b/motorengine/query_builder/node.py @@ -164,7 +164,7 @@ class User(Document): age = IntField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: querying_with_Q diff --git a/motorengine/queryset.py b/motorengine/queryset.py index 1511a91..00bfa23 100644 --- a/motorengine/queryset.py +++ b/motorengine/queryset.py @@ -51,7 +51,7 @@ class User(Document): name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_create @@ -221,7 +221,7 @@ class User(Document): name = StringField() io_loop = tornado.ioloop.IOLoop.instance() - connect("test", host="localhost", port=4445, io_loop=io_loop) + connect("test", host="localhost", port=27017, io_loop=io_loop) .. testcode:: saving_delete diff --git a/setup.py b/setup.py index 30fc71f..29943bb 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,7 @@ packages=find_packages(), include_package_data=True, install_requires=[ - 'pymongo==2.5', + 'pymongo', 'tornado', 'motor', 'six', diff --git a/tests/__init__.py b/tests/__init__.py index e7facbf..634bd3e 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -12,7 +12,7 @@ class AsyncTestCase(TornadoAsyncTestCase): def setUp(self, auto_connect=True): super(AsyncTestCase, self).setUp() if auto_connect: - self.db = connect("test", host="localhost", port=4445, io_loop=self.io_loop) + self.db = connect("test", host="localhost", port=27017, io_loop=self.io_loop) def tearDown(self): motorengine.connection.cleanup() diff --git a/tests/integration/base.py b/tests/integration/base.py index cf6fae9..bbfbe98 100644 --- a/tests/integration/base.py +++ b/tests/integration/base.py @@ -12,8 +12,8 @@ class BaseIntegrationTest(AsyncTestCase): def setUp(self, auto_connect=True): super(AsyncTestCase, self).setUp() if auto_connect: - self.db = motorengine.connect("test", host="localhost", port=4445, io_loop=self.io_loop) - mongoengine.connect("test", host="localhost", port=4445) + self.db = motorengine.connect("test", host="localhost", port=27017, io_loop=self.io_loop) + mongoengine.connect("test", host="localhost", port=27017) def tearDown(self): motorengine.connection.cleanup() diff --git a/tests/integration/fields/test_binary_field.py b/tests/integration/fields/test_binary_field.py index 060eadb..d986454 100644 --- a/tests/integration/fields/test_binary_field.py +++ b/tests/integration/fields/test_binary_field.py @@ -23,8 +23,7 @@ class MotorDocument(motorengine.Document): byte = motorengine.BinaryField() -class TestStringField(BaseIntegrationTest): - @gen_test +class TestBinaryField(BaseIntegrationTest): def test_can_integrate(self): mongo_document = MongoDocument(byte=six.b("some_string")).save() diff --git a/tests/test_connect.py b/tests/test_connect.py index c300e18..168e6cb 100644 --- a/tests/test_connect.py +++ b/tests/test_connect.py @@ -15,14 +15,14 @@ def setUp(self): super(TestConnect, self).setUp(auto_connect=False) def test_can_connect_to_a_database(self): - db = connect('test', host="localhost", port=4445, io_loop=self.io_loop) + db = connect('test', host="localhost", port=27017, io_loop=self.io_loop) args, kwargs = self.exec_async(db.ping) ping_result = args[0]['ok'] expect(ping_result).to_equal(1.0) def test_connect_to_replica_set(self): - db = connect('test', host="localhost:27017,localhost:27018", replicaSet="rs0", port=4445, io_loop=self.io_loop) + db = connect('test', host="localhost:27017,localhost:27018", replicaSet="rs0", port=27017, io_loop=self.io_loop) args, kwargs = self.exec_async(db.ping) ping_result = args[0]['ok'] @@ -30,7 +30,7 @@ def test_connect_to_replica_set(self): def test_connect_to_replica_set_with_invalid_replicaset_name(self): try: - connect('test', host="localhost:27017,localhost:27018", replicaSet=0, port=4445, io_loop=self.io_loop) + connect('test', host="localhost:27017,localhost:27018", replicaSet=0, port=27017, io_loop=self.io_loop) except ConnectionError: exc_info = sys.exc_info()[1] expect(str(exc_info)).to_include('the replicaSet keyword parameter is required') diff --git a/tests/test_database.py b/tests/test_database.py index d69a079..014de60 100644 --- a/tests/test_database.py +++ b/tests/test_database.py @@ -10,7 +10,7 @@ class TestDatabase(AsyncTestCase): def test_database_ping(self): - db = connect("test", host="localhost", port=4445, io_loop=self.io_loop) + db = connect("test", host="localhost", port=27017, io_loop=self.io_loop) args, kwargs = self.exec_async(db.ping) ping_result = args[0]['ok'] @@ -19,6 +19,6 @@ def test_database_ping(self): disconnect() def test_database_returns_collection_when_asked_for_a_name(self): - db = connect("test", host="localhost", port=4445, io_loop=self.io_loop) + db = connect("test", host="localhost", port=27017, io_loop=self.io_loop) expect(db.something).to_be_instance_of(motor.MotorCollection) diff --git a/tests/test_document.py b/tests/test_document.py index df6ffed..dd85572 100644 --- a/tests/test_document.py +++ b/tests/test_document.py @@ -904,7 +904,7 @@ class UniqueFieldDocument(Document): self.wait() except UniqueKeyViolationError: err = sys.exc_info()[1] - expect(err).to_have_an_error_message_of('The index "test.UniqueFieldDocument.$name_1" was violated when trying to save this "UniqueFieldDocument" (error code: E11000).') + expect(err).to_have_an_error_message_of('The index "caused" was violated when trying to save this "UniqueFieldDocument" (error code: insertDocument).') else: assert False, "Should not have gotten this far."