Compare commits
3 Commits
add-rename
...
test-write
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3e44ca4577 | ||
|
|
d378bd09a5 | ||
|
|
2ee8984b44 |
@@ -5,7 +5,7 @@ __all__ = ('UPDATE_OPERATORS', 'get_document', '_document_registry')
|
|||||||
|
|
||||||
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',
|
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',
|
||||||
'push_all', 'pull', 'pull_all', 'add_to_set',
|
'push_all', 'pull', 'pull_all', 'add_to_set',
|
||||||
'set_on_insert', 'min', 'max'])
|
'set_on_insert', 'min', 'max', 'rename'])
|
||||||
|
|
||||||
|
|
||||||
_document_registry = {}
|
_document_registry = {}
|
||||||
|
|||||||
@@ -1232,6 +1232,19 @@ class InstanceTest(unittest.TestCase):
|
|||||||
self.assertEqual(person.name, None)
|
self.assertEqual(person.name, None)
|
||||||
self.assertEqual(person.age, None)
|
self.assertEqual(person.age, None)
|
||||||
|
|
||||||
|
def test_update_rename_operator(self):
|
||||||
|
"""Test the $rename operator."""
|
||||||
|
coll = self.Person._get_collection()
|
||||||
|
doc = self.Person(name='John').save()
|
||||||
|
raw_doc = coll.find_one({'_id': doc.pk})
|
||||||
|
self.assertEqual(set(raw_doc.keys()), set(['_id', '_cls', 'name']))
|
||||||
|
|
||||||
|
doc.update(rename__name='first_name')
|
||||||
|
raw_doc = coll.find_one({'_id': doc.pk})
|
||||||
|
self.assertEqual(set(raw_doc.keys()),
|
||||||
|
set(['_id', '_cls', 'first_name']))
|
||||||
|
self.assertEqual(raw_doc['first_name'], 'John')
|
||||||
|
|
||||||
def test_inserts_if_you_set_the_pk(self):
|
def test_inserts_if_you_set_the_pk(self):
|
||||||
p1 = self.Person(name='p1', id=bson.ObjectId()).save()
|
p1 = self.Person(name='p1', id=bson.ObjectId()).save()
|
||||||
p2 = self.Person(name='p2')
|
p2 = self.Person(name='p2')
|
||||||
|
|||||||
@@ -296,6 +296,19 @@ class ConnectionTest(unittest.TestCase):
|
|||||||
conn = get_connection('t2')
|
conn = get_connection('t2')
|
||||||
self.assertFalse(get_tz_awareness(conn))
|
self.assertFalse(get_tz_awareness(conn))
|
||||||
|
|
||||||
|
def test_write_concern(self):
|
||||||
|
"""Ensure write concern can be specified in connect() via
|
||||||
|
a kwarg or as part of the connection URI.
|
||||||
|
"""
|
||||||
|
conn1 = connect(alias='conn1', host='mongodb://localhost/testing?w=1&j=true')
|
||||||
|
conn2 = connect('testing', alias='conn2', w=1, j=True)
|
||||||
|
if IS_PYMONGO_3:
|
||||||
|
self.assertEqual(conn1.write_concern.document, {'w': 1, 'j': True})
|
||||||
|
self.assertEqual(conn2.write_concern.document, {'w': 1, 'j': True})
|
||||||
|
else:
|
||||||
|
self.assertEqual(dict(conn1.write_concern), {'w': 1, 'j': True})
|
||||||
|
self.assertEqual(dict(conn2.write_concern), {'w': 1, 'j': True})
|
||||||
|
|
||||||
def test_datetime(self):
|
def test_datetime(self):
|
||||||
connect('mongoenginetest', tz_aware=True)
|
connect('mongoenginetest', tz_aware=True)
|
||||||
d = datetime.datetime(2010, 5, 5, tzinfo=utc)
|
d = datetime.datetime(2010, 5, 5, tzinfo=utc)
|
||||||
|
|||||||
Reference in New Issue
Block a user