Skip to content

Commit

Permalink
Updating to newer versions of motor and pymongo
Browse files Browse the repository at this point in the history
  • Loading branch information
heynemann committed May 21, 2014
1 parent dc5d873 commit 5015965
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 39 deletions.
6 changes: 3 additions & 3 deletions benchmark/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions benchmark/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
10 changes: 5 additions & 5 deletions docs/source/connecting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
------------
Expand Down Expand Up @@ -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.
Expand All @@ -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")
20 changes: 12 additions & 8 deletions docs/source/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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) \
Expand All @@ -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
Expand All @@ -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

Expand Down
4 changes: 2 additions & 2 deletions docs/source/modeling.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions docs/source/saving.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion motorengine/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion motorengine/query_builder/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions motorengine/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
packages=find_packages(),
include_package_data=True,
install_requires=[
'pymongo==2.5',
'pymongo',
'tornado',
'motor',
'six',
Expand Down
2 changes: 1 addition & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions tests/integration/fields/test_binary_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 3 additions & 3 deletions tests/test_connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ 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']
expect(ping_result).to_equal(1.0)

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')
Expand Down
4 changes: 2 additions & 2 deletions tests/test_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']
Expand All @@ -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)
2 changes: 1 addition & 1 deletion tests/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down

0 comments on commit 5015965

Please sign in to comment.