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

Method test_max

test/asynchronous/test_cursor.py:511–547  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

509 a.limit(5)
510
511 async def test_max(self):
512 db = self.db
513 await db.test.drop()
514 j_index = [("j", ASCENDING)]
515 await db.test.create_index(j_index)
516
517 await db.test.insert_many([{"j": j, "k": j} for j in range(10)])
518
519 def find(max_spec, expected_index):
520 return db.test.find().max(max_spec).hint(expected_index)
521
522 cursor = find([("j", 3)], j_index)
523 self.assertEqual(len(await cursor.to_list()), 3)
524
525 # Tuple.
526 cursor = find((("j", 3),), j_index)
527 self.assertEqual(len(await cursor.to_list()), 3)
528
529 # Compound index.
530 index_keys = [("j", ASCENDING), ("k", ASCENDING)]
531 await db.test.create_index(index_keys)
532 cursor = find([("j", 3), ("k", 3)], index_keys)
533 self.assertEqual(len(await cursor.to_list()), 3)
534
535 # Wrong order.
536 cursor = find([("k", 3), ("j", 3)], index_keys)
537 with self.assertRaises(OperationFailure):
538 await cursor.to_list()
539
540 # No such index.
541 cursor = find([("k", 3)], "k")
542 with self.assertRaises(OperationFailure):
543 await cursor.to_list()
544 with self.assertRaises(TypeError):
545 db.test.find().max(10) # type: ignore[arg-type]
546 with self.assertRaises(TypeError):
547 db.test.find().max({"j": 10}) # type: ignore[arg-type]
548
549 async def test_min(self):
550 db = self.db

Callers

nothing calls this directly

Calls 6

dropMethod · 0.45
create_indexMethod · 0.45
insert_manyMethod · 0.45
to_listMethod · 0.45
maxMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected