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

Method test_single_error_ordered_batch

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

Source from the content-addressed store, hash-verified

502 )
503
504 def test_single_error_ordered_batch(self):
505 self.coll.create_index("a", unique=True)
506 self.addCleanup(self.coll.drop_index, [("a", 1)])
507 requests: list = [
508 InsertOne({"b": 1, "a": 1}),
509 UpdateOne({"b": 2}, {"$set": {"a": 1}}, upsert=True),
510 InsertOne({"b": 3, "a": 2}),
511 ]
512 try:
513 self.coll.bulk_write(requests)
514 except BulkWriteError as exc:
515 result = exc.details
516 self.assertEqual(exc.code, 65)
517 else:
518 self.fail("Error not raised")
519
520 self.assertEqualResponse(
521 {
522 "nMatched": 0,
523 "nModified": 0,
524 "nUpserted": 0,
525 "nInserted": 1,
526 "nRemoved": 0,
527 "upserted": [],
528 "writeConcernErrors": [],
529 "writeErrors": [
530 {
531 "index": 1,
532 "code": 11000,
533 "errmsg": "...",
534 "op": {
535 "q": {"b": 2},
536 "u": {"$set": {"a": 1}},
537 "multi": False,
538 "upsert": True,
539 },
540 }
541 ],
542 },
543 result,
544 )
545
546 def test_multiple_error_ordered_batch(self):
547 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