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

Method test_insert_find_one

test/test_database.py:526–552  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

524
525 # TODO some of these tests belong in the collection level testing.
526 def test_insert_find_one(self):
527 db = self.client.pymongo_test
528 db.test.drop()
529
530 a_doc = SON({"hello": "world"})
531 a_key = (db.test.insert_one(a_doc)).inserted_id
532 self.assertIsInstance(a_doc["_id"], ObjectId)
533 self.assertEqual(a_doc["_id"], a_key)
534 self.assertEqual(a_doc, db.test.find_one({"_id": a_doc["_id"]}))
535 self.assertEqual(a_doc, db.test.find_one(a_key))
536 self.assertEqual(None, db.test.find_one(ObjectId()))
537 self.assertEqual(a_doc, db.test.find_one({"hello": "world"}))
538 self.assertEqual(None, db.test.find_one({"hello": "test"}))
539
540 b = db.test.find_one()
541 assert b is not None
542 b["hello"] = "mike"
543 db.test.replace_one({"_id": b["_id"]}, b)
544
545 self.assertNotEqual(a_doc, db.test.find_one(a_key))
546 self.assertEqual(b, db.test.find_one(a_key))
547 self.assertEqual(b, db.test.find_one())
548
549 count = 0
550 for _ in db.test.find():
551 count += 1
552 self.assertEqual(count, 1)
553
554 def test_long(self):
555 db = self.client.pymongo_test

Callers

nothing calls this directly

Calls 7

SONClass · 0.90
ObjectIdClass · 0.90
dropMethod · 0.45
insert_oneMethod · 0.45
find_oneMethod · 0.45
replace_oneMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected