MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / test_single_error_unordered_batch

Method test_single_error_unordered_batch

test/test_bulk.py:615–656  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

613 )
614
615 def test_single_error_unordered_batch(self):
616 self.coll.create_index("a", unique=True)
617 self.addCleanup(self.coll.drop_index, [("a", 1)])
618 requests: list = [
619 InsertOne({"b": 1, "a": 1}),
620 UpdateOne({"b": 2}, {"$set": {"a": 1}}, upsert=True),
621 InsertOne({"b": 3, "a": 2}),
622 ]
623
624 try:
625 self.coll.bulk_write(requests, ordered=False)
626 except BulkWriteError as exc:
627 result = exc.details
628 self.assertEqual(exc.code, 65)
629 else:
630 self.fail("Error not raised")
631
632 self.assertEqualResponse(
633 {
634 "nMatched": 0,
635 "nModified": 0,
636 "nUpserted": 0,
637 "nInserted": 2,
638 "nRemoved": 0,
639 "upserted": [],
640 "writeConcernErrors": [],
641 "writeErrors": [
642 {
643 "index": 1,
644 "code": 11000,
645 "errmsg": "...",
646 "op": {
647 "q": {"b": 2},
648 "u": {"$set": {"a": 1}},
649 "multi": False,
650 "upsert": True,
651 },
652 }
653 ],
654 },
655 result,
656 )
657
658 def test_multiple_error_unordered_batch(self):
659 self.coll.create_index("a", unique=True)

Callers

nothing calls this directly

Calls 6

InsertOneClass · 0.85
UpdateOneClass · 0.85
addCleanupMethod · 0.80
create_indexMethod · 0.45
bulk_writeMethod · 0.45
assertEqualResponseMethod · 0.45

Tested by

no test coverage detected