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

Method test_aggregation_cursor

test/test_collection.py:1574–1603  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1572 self.assertIsInstance(cursor, CommandCursor)
1573
1574 def test_aggregation_cursor(self):
1575 db = self.db
1576 if client_context.has_secondaries:
1577 # Test that getMore messages are sent to the right server.
1578 db = self.client.get_database(
1579 db.name,
1580 read_preference=ReadPreference.SECONDARY,
1581 write_concern=WriteConcern(w=self.w),
1582 )
1583
1584 for collection_size in (10, 1000):
1585 db.drop_collection("test")
1586 db.test.insert_many([{"_id": i} for i in range(collection_size)])
1587 expected_sum = sum(range(collection_size))
1588 # Use batchSize to ensure multiple getMore messages
1589 cursor = db.test.aggregate([{"$project": {"_id": "$_id"}}], batchSize=5)
1590
1591 self.assertEqual(expected_sum, sum(doc["_id"] for doc in cursor.to_list()))
1592
1593 # Test that batchSize is handled properly.
1594 cursor = db.test.aggregate([], batchSize=5)
1595 self.assertEqual(5, len(cursor._data))
1596 # Force a getMore
1597 cursor._data.clear()
1598 next(cursor)
1599 # batchSize - 1
1600 self.assertEqual(4, len(cursor._data))
1601 # Exhaust the cursor. There shouldn't be any errors.
1602 for _doc in cursor:
1603 pass
1604
1605 def test_aggregation_cursor_alive(self):
1606 self.db.test.delete_many({})

Callers

nothing calls this directly

Calls 8

WriteConcernClass · 0.90
nextFunction · 0.90
get_databaseMethod · 0.45
drop_collectionMethod · 0.45
insert_manyMethod · 0.45
aggregateMethod · 0.45
to_listMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected