(self)
| 384 | self.client.admin.command("configureFailPoint", "maxTimeAlwaysTimeOut", mode="off") |
| 385 | |
| 386 | def test_list_indexes(self): |
| 387 | db = self.db |
| 388 | db.test.drop() |
| 389 | db.test.insert_one({}) # create collection |
| 390 | |
| 391 | def map_indexes(indexes): |
| 392 | return {index["name"]: index for index in indexes} |
| 393 | |
| 394 | indexes = (db.test.list_indexes()).to_list() |
| 395 | self.assertEqual(len(indexes), 1) |
| 396 | self.assertIn("_id_", map_indexes(indexes)) |
| 397 | |
| 398 | db.test.create_index("hello") |
| 399 | indexes = (db.test.list_indexes()).to_list() |
| 400 | self.assertEqual(len(indexes), 2) |
| 401 | self.assertEqual(map_indexes(indexes)["hello_1"]["key"], SON([("hello", ASCENDING)])) |
| 402 | |
| 403 | db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)], unique=True) |
| 404 | indexes = (db.test.list_indexes()).to_list() |
| 405 | self.assertEqual(len(indexes), 3) |
| 406 | index_map = map_indexes(indexes) |
| 407 | self.assertEqual( |
| 408 | index_map["hello_-1_world_1"]["key"], SON([("hello", DESCENDING), ("world", ASCENDING)]) |
| 409 | ) |
| 410 | self.assertEqual(True, index_map["hello_-1_world_1"]["unique"]) |
| 411 | |
| 412 | # List indexes on a collection that does not exist. |
| 413 | indexes = (db.does_not_exist.list_indexes()).to_list() |
| 414 | self.assertEqual(len(indexes), 0) |
| 415 | |
| 416 | # List indexes on a database that does not exist. |
| 417 | indexes = (db.does_not_exist.list_indexes()).to_list() |
| 418 | self.assertEqual(len(indexes), 0) |
| 419 | |
| 420 | def test_index_info(self): |
| 421 | db = self.db |
nothing calls this directly
no test coverage detected