Added update() convenience method to a document

Thanks to @dcrosta for the initial code
[closes #229]
This commit is contained in:
Ross Lawley
2011-07-13 14:15:46 +01:00
parent 7a3412dc13
commit a4c197a83c
3 changed files with 36 additions and 1 deletions

View File

@@ -1203,6 +1203,29 @@ class DocumentTest(unittest.TestCase):
self.assertEqual(person.name, None)
self.assertEqual(person.age, None)
def test_document_update(self):
def update_not_saved_raises():
person = self.Person(name='dcrosta')
person.update(set__name='Dan Crosta')
self.assertRaises(OperationError, update_not_saved_raises)
author = self.Person(name='dcrosta')
author.save()
author.update(set__name='Dan Crosta')
author.reload()
p1 = self.Person.objects.first()
self.assertEquals(p1.name, author.name)
def update_no_value_raises():
person = self.Person.objects.first()
person.update()
self.assertRaises(OperationError, update_no_value_raises)
def test_embedded_update(self):
"""
Test update on `EmbeddedDocumentField` fields

View File

@@ -242,7 +242,7 @@ class QuerySetTest(unittest.TestCase):
self.Person.objects(pk=author.pk).update({})
def update_one_raises():
self.Person.objects(pk=author.pk).update({})
self.Person.objects(pk=author.pk).update_one({})
self.assertRaises(OperationError, update_raises)
self.assertRaises(OperationError, update_one_raises)