can't iterate on a collection

This commit is contained in:
Mike Dirolf 2009-01-23 10:00:49 -05:00
parent 601b1618ad
commit 163680bc16
2 changed files with 14 additions and 0 deletions

View File

@ -367,3 +367,9 @@ class Collection(object):
del options["create"]
return options
def __iter__(self):
return self
def next(self):
raise TypeError("'Collection' object is not iterable")

View File

@ -137,6 +137,14 @@ class TestCollection(unittest.TestCase):
self.assertEqual(db.test.find().count(), 1)
self.assertEqual(doc, db.test.find_one())
def test_iteration(self):
db = self.db
def iterate():
[a for a in db.test]
self.assertRaises(TypeError, iterate)
# TODO enable this test when Mongo insert multiple is fixed
# OR remove the insert a list functionality from the driver
# def test_insert_multiple(self):