PYTHON-1690: Fix error message when insert_many is given a single RawBSONDocument instead of a list (#580)
This commit is contained in:
parent
80adc13195
commit
94f4de1f2e
@ -686,7 +686,9 @@ class Collection(common.BaseObject):
|
||||
|
||||
.. versionadded:: 3.0
|
||||
"""
|
||||
if not isinstance(documents, abc.Iterable) or not documents:
|
||||
if (not isinstance(documents, abc.Iterable)
|
||||
or isinstance(documents, abc.Mapping)
|
||||
or not documents):
|
||||
raise TypeError("documents must be a non-empty list")
|
||||
inserted_ids = []
|
||||
def gen():
|
||||
|
||||
@ -786,6 +786,25 @@ class TestCollection(IntegrationTest):
|
||||
self.assertFalse(result.acknowledged)
|
||||
self.assertEqual(20, db.test.count_documents({}))
|
||||
|
||||
def test_insert_many_invalid(self):
|
||||
db = self.db
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "documents must be a non-empty list"):
|
||||
db.test.insert_many({})
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "documents must be a non-empty list"):
|
||||
db.test.insert_many([])
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "documents must be a non-empty list"):
|
||||
db.test.insert_many(1)
|
||||
|
||||
with self.assertRaisesRegex(
|
||||
TypeError, "documents must be a non-empty list"):
|
||||
db.test.insert_many(RawBSONDocument(encode({'_id': 2})))
|
||||
|
||||
def test_delete_one(self):
|
||||
self.db.test.drop()
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user