Removed pool_size from connect, minor tidyup
This commit is contained in:
parent
df5b1f3806
commit
89f505bb13
@ -7,7 +7,6 @@ __all__ = ['ConnectionError', 'connect']
|
|||||||
_connection_settings = {
|
_connection_settings = {
|
||||||
'host': 'localhost',
|
'host': 'localhost',
|
||||||
'port': 27017,
|
'port': 27017,
|
||||||
'pool_size': 1,
|
|
||||||
}
|
}
|
||||||
_connection = None
|
_connection = None
|
||||||
|
|
||||||
|
@ -78,9 +78,9 @@ class Document(BaseDocument):
|
|||||||
object_id = collection.save(doc, safe=safe)
|
object_id = collection.save(doc, safe=safe)
|
||||||
except pymongo.errors.OperationFailure, err:
|
except pymongo.errors.OperationFailure, err:
|
||||||
message = 'Could not save document (%s)'
|
message = 'Could not save document (%s)'
|
||||||
if u'duplicate key' in err.message:
|
if u'duplicate key' in unicode(err):
|
||||||
message = u'Tried to save duplicate unique keys (%s)'
|
message = u'Tried to save duplicate unique keys (%s)'
|
||||||
raise OperationError(message % err.message)
|
raise OperationError(message % unicode(err))
|
||||||
id_field = self._meta['id_field']
|
id_field = self._meta['id_field']
|
||||||
self[id_field] = self._fields[id_field].to_python(object_id)
|
self[id_field] = self._fields[id_field].to_python(object_id)
|
||||||
|
|
||||||
@ -95,7 +95,8 @@ class Document(BaseDocument):
|
|||||||
try:
|
try:
|
||||||
self.__class__.objects(**{id_field: object_id}).delete(safe=safe)
|
self.__class__.objects(**{id_field: object_id}).delete(safe=safe)
|
||||||
except pymongo.errors.OperationFailure, err:
|
except pymongo.errors.OperationFailure, err:
|
||||||
raise OperationError(u'Could not delete document (%s)' % err.message)
|
message = u'Could not delete document (%s)' % err.message
|
||||||
|
raise OperationError(message)
|
||||||
|
|
||||||
def reload(self):
|
def reload(self):
|
||||||
"""Reloads all attributes from the database.
|
"""Reloads all attributes from the database.
|
||||||
|
@ -71,7 +71,8 @@ class FloatField(BaseField):
|
|||||||
return float(value)
|
return float(value)
|
||||||
|
|
||||||
def validate(self, value):
|
def validate(self, value):
|
||||||
if isinstance(value, int): value = float(value)
|
if isinstance(value, int):
|
||||||
|
value = float(value)
|
||||||
assert isinstance(value, float)
|
assert isinstance(value, float)
|
||||||
|
|
||||||
if self.min_value is not None and value < self.min_value:
|
if self.min_value is not None and value < self.min_value:
|
||||||
|
@ -520,9 +520,10 @@ class QuerySet(object):
|
|||||||
self._collection.update(self._query, update, safe=safe_update,
|
self._collection.update(self._query, update, safe=safe_update,
|
||||||
multi=True)
|
multi=True)
|
||||||
except pymongo.errors.OperationFailure, err:
|
except pymongo.errors.OperationFailure, err:
|
||||||
if err.message == u'multi not coded yet':
|
if unicode(err) == u'multi not coded yet':
|
||||||
raise OperationError(u'update() method requires MongoDB 1.1.3+')
|
message = u'update() method requires MongoDB 1.1.3+'
|
||||||
raise OperationError(u'Update failed (%s)' % err.message)
|
raise OperationError(message)
|
||||||
|
raise OperationError(u'Update failed (%s)' % unicode(err))
|
||||||
|
|
||||||
def update_one(self, safe_update=True, **update):
|
def update_one(self, safe_update=True, **update):
|
||||||
"""Perform an atomic update on first field matched by the query.
|
"""Perform an atomic update on first field matched by the query.
|
||||||
|
@ -106,7 +106,7 @@ class FieldTest(unittest.TestCase):
|
|||||||
person.height = 1.89
|
person.height = 1.89
|
||||||
person.validate()
|
person.validate()
|
||||||
|
|
||||||
person.height = 2
|
person.height = '2.0'
|
||||||
self.assertRaises(ValidationError, person.validate)
|
self.assertRaises(ValidationError, person.validate)
|
||||||
person.height = 0.01
|
person.height = 0.01
|
||||||
self.assertRaises(ValidationError, person.validate)
|
self.assertRaises(ValidationError, person.validate)
|
||||||
|
@ -21,7 +21,7 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
"""Ensure that a QuerySet is correctly initialised by QuerySetManager.
|
"""Ensure that a QuerySet is correctly initialised by QuerySetManager.
|
||||||
"""
|
"""
|
||||||
self.assertTrue(isinstance(self.Person.objects, QuerySet))
|
self.assertTrue(isinstance(self.Person.objects, QuerySet))
|
||||||
self.assertEqual(self.Person.objects._collection.name(),
|
self.assertEqual(self.Person.objects._collection.name,
|
||||||
self.Person._meta['collection'])
|
self.Person._meta['collection'])
|
||||||
self.assertTrue(isinstance(self.Person.objects._collection,
|
self.assertTrue(isinstance(self.Person.objects._collection,
|
||||||
pymongo.collection.Collection))
|
pymongo.collection.Collection))
|
||||||
@ -294,6 +294,8 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
BlogPost.drop_collection()
|
BlogPost.drop_collection()
|
||||||
|
|
||||||
def test_q(self):
|
def test_q(self):
|
||||||
|
"""Ensure that Q objects may be used to query for documents.
|
||||||
|
"""
|
||||||
class BlogPost(Document):
|
class BlogPost(Document):
|
||||||
publish_date = DateTimeField()
|
publish_date = DateTimeField()
|
||||||
published = BooleanField()
|
published = BooleanField()
|
||||||
@ -618,6 +620,8 @@ class QuerySetTest(unittest.TestCase):
|
|||||||
class QTest(unittest.TestCase):
|
class QTest(unittest.TestCase):
|
||||||
|
|
||||||
def test_or_and(self):
|
def test_or_and(self):
|
||||||
|
"""Ensure that Q objects may be combined correctly.
|
||||||
|
"""
|
||||||
q1 = Q(name='test')
|
q1 = Q(name='test')
|
||||||
q2 = Q(age__gte=18)
|
q2 = Q(age__gte=18)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user