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

Method test_gridfsbucket_cursor

test/test_session.py:597–646  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

595 )
596
597 def test_gridfsbucket_cursor(self):
598 client = self.client
599 bucket = GridFSBucket(client.pymongo_test)
600
601 for file_id in 1, 2:
602 stream = bucket.open_upload_stream_with_id(file_id, str(file_id))
603 stream.write(b"a" * 1048576)
604 stream.close()
605
606 with client.start_session() as s:
607 cursor = bucket.find(session=s)
608 for f in cursor:
609 f.read()
610
611 self.assertFalse(s.has_ended)
612
613 self.assertTrue(s.has_ended)
614
615 # No explicit session.
616 cursor = bucket.find(batch_size=1)
617 files = [cursor.next()]
618
619 s = cursor._session
620 self.assertFalse(s.has_ended)
621 cursor.__del__()
622
623 self.assertTrue(s.has_ended)
624 self.assertIsNone(cursor._session)
625
626 # Files are still valid, they use their own sessions.
627 for f in files:
628 f.read()
629
630 # Explicit session.
631 with client.start_session() as s:
632 cursor = bucket.find(session=s)
633 assert cursor.session is not None
634 s = cursor.session
635 files = cursor.to_list()
636 cursor.__del__()
637 self.assertFalse(s.has_ended)
638
639 for f in files:
640 f.read()
641
642 for f in files:
643 # Attempt to read the file again.
644 f.seek(0)
645 with self.assertRaisesRegex(InvalidOperation, "ended session"):
646 f.read()
647
648 def test_aggregate(self):
649 client = self.client

Callers

nothing calls this directly

Calls 11

findMethod · 0.95
GridFSBucketClass · 0.90
writeMethod · 0.45
closeMethod · 0.45
start_sessionMethod · 0.45
readMethod · 0.45
nextMethod · 0.45
__del__Method · 0.45
to_listMethod · 0.45
seekMethod · 0.45

Tested by

no test coverage detected