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

Method test_client_generated_upsert_id

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

Source from the content-addressed store, hash-verified

365 self.assertEqual(1, self.coll.count_documents({"x": 1}))
366
367 def test_client_generated_upsert_id(self):
368 result = self.coll.bulk_write(
369 [
370 UpdateOne({"_id": 0}, {"$set": {"a": 0}}, upsert=True),
371 ReplaceOne({"a": 1}, {"_id": 1}, upsert=True),
372 # This is just here to make the counts right in all cases.
373 ReplaceOne({"_id": 2}, {"_id": 2}, upsert=True),
374 ]
375 )
376 self.assertEqualResponse(
377 {
378 "nMatched": 0,
379 "nModified": 0,
380 "nUpserted": 3,
381 "nInserted": 0,
382 "nRemoved": 0,
383 "upserted": [
384 {"index": 0, "_id": 0},
385 {"index": 1, "_id": 1},
386 {"index": 2, "_id": 2},
387 ],
388 },
389 result.bulk_api_result,
390 )
391
392 def test_upsert_uuid_standard(self):
393 options = CodecOptions(uuid_representation=UuidRepresentation.STANDARD)

Callers

nothing calls this directly

Calls 4

UpdateOneClass · 0.85
ReplaceOneClass · 0.85
bulk_writeMethod · 0.45
assertEqualResponseMethod · 0.45

Tested by

no test coverage detected