From 06ae7612b07d87f261d314df97e7b9bcf1ce5b19 Mon Sep 17 00:00:00 2001 From: "A. Jesse Jiryu Davis" Date: Thu, 17 Oct 2013 16:07:08 -0400 Subject: [PATCH] More tests for update with manipulate and for insert with generator. PYTHON-585 --- test/test_collection.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test_collection.py b/test/test_collection.py index 23fa6df5b..caa4016cc 100644 --- a/test/test_collection.py +++ b/test/test_collection.py @@ -617,6 +617,10 @@ class TestCollection(unittest.TestCase): self.assertEqual(5, db.test.count()) db.test.remove({}) + db.test.insert(({'a': i} for i in xrange(5)), manipulate=True) + self.assertEqual(5, db.test.count()) + db.test.remove({}) + def test_remove_all(self): self.db.test.remove() self.assertEqual(0, self.db.test.count()) @@ -1058,6 +1062,23 @@ class TestCollection(unittest.TestCase): {'_id': 1, 'a': 1}, db.test.find_one()) + class AddField(SONManipulator): + def transform_incoming(self, son, collection): + son['field'] = 'value' + return son + + db.add_son_manipulator(AddField()) + db.test.update({'_id': 1}, {'a': 2}, manipulate=False) + self.assertEqual( + {'_id': 1, 'a': 2}, + db.test.find_one()) + + db.test.update({'_id': 1}, {'a': 3}, manipulate=True) + self.assertEqual( + {'_id': 1, 'a': 3, 'field': 'value'}, + db.test.find_one()) + + def test_multi_update(self): db = self.db if not version.at_least(db.connection, (1, 1, 3, -1)):