MCPcopy Create free account
hub / github.com/mongodb/mongo-python-driver / test_gridfs_find

Method test_gridfs_find

test/asynchronous/test_gridfs.py:457–485  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

455 await f.close()
456
457 async def test_gridfs_find(self):
458 await self.fs.put(b"test2", filename="two")
459 await asyncio.sleep(0.01)
460 await self.fs.put(b"test2+", filename="two")
461 await asyncio.sleep(0.01)
462 await self.fs.put(b"test1", filename="one")
463 await asyncio.sleep(0.01)
464 await self.fs.put(b"test2++", filename="two")
465 files = self.db.fs.files
466 self.assertEqual(3, await files.count_documents({"filename": "two"}))
467 self.assertEqual(4, await files.count_documents({}))
468 cursor = self.fs.find(no_cursor_timeout=False).sort("uploadDate", -1).skip(1).limit(2)
469 gout = await cursor.next()
470 self.assertEqual(b"test1", await gout.read())
471 await cursor.rewind()
472 gout = await cursor.next()
473 self.assertEqual(b"test1", await gout.read())
474 gout = await cursor.next()
475 self.assertEqual(b"test2+", await gout.read())
476 with self.assertRaises(StopAsyncIteration):
477 await cursor.__anext__()
478 await cursor.rewind()
479 items = await cursor.to_list()
480 self.assertEqual(len(items), 2)
481 await cursor.rewind()
482 items = await cursor.to_list(1)
483 self.assertEqual(len(items), 1)
484 await cursor.close()
485 self.assertRaises(TypeError, self.fs.find, {}, {"_id": True})
486
487 async def test_delete_not_initialized(self):
488 # Creating a cursor with invalid arguments will not run __init__

Callers

nothing calls this directly

Calls 12

putMethod · 0.45
count_documentsMethod · 0.45
limitMethod · 0.45
skipMethod · 0.45
sortMethod · 0.45
findMethod · 0.45
nextMethod · 0.45
readMethod · 0.45
rewindMethod · 0.45
__anext__Method · 0.45
to_listMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected