(self)
| 284 | self.db.coll.create_indexes([IndexModel("a")], commitQuorum="majority") |
| 285 | |
| 286 | def test_create_index(self): |
| 287 | db = self.db |
| 288 | |
| 289 | with self.assertRaises(TypeError): |
| 290 | db.test.create_index(5) # type: ignore[arg-type] |
| 291 | with self.assertRaises(ValueError): |
| 292 | db.test.create_index([]) |
| 293 | |
| 294 | db.test.drop_indexes() |
| 295 | db.test.insert_one({}) |
| 296 | self.assertEqual(len(db.test.index_information()), 1) |
| 297 | |
| 298 | db.test.create_index("hello") |
| 299 | db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)]) |
| 300 | |
| 301 | # Tuple instead of list. |
| 302 | db.test.create_index((("world", ASCENDING),)) |
| 303 | |
| 304 | self.assertEqual(len(db.test.index_information()), 4) |
| 305 | |
| 306 | db.test.drop_indexes() |
| 307 | ix = db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)], name="hello_world") |
| 308 | self.assertEqual(ix, "hello_world") |
| 309 | |
| 310 | db.test.drop_indexes() |
| 311 | self.assertEqual(len(db.test.index_information()), 1) |
| 312 | db.test.create_index("hello") |
| 313 | self.assertIn("hello_1", db.test.index_information()) |
| 314 | |
| 315 | db.test.drop_indexes() |
| 316 | self.assertEqual(len(db.test.index_information()), 1) |
| 317 | db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)]) |
| 318 | self.assertIn("hello_-1_world_1", db.test.index_information()) |
| 319 | |
| 320 | db.test.drop_indexes() |
| 321 | db.test.create_index([("hello", DESCENDING), ("world", ASCENDING)], name=None) |
| 322 | self.assertIn("hello_-1_world_1", db.test.index_information()) |
| 323 | |
| 324 | db.test.drop() |
| 325 | db.test.insert_one({"a": 1}) |
| 326 | db.test.insert_one({"a": 1}) |
| 327 | with self.assertRaises(DuplicateKeyError): |
| 328 | db.test.create_index("a", unique=True) |
| 329 | |
| 330 | with self.write_concern_collection() as coll: |
| 331 | coll.create_index([("hello", DESCENDING)]) |
| 332 | |
| 333 | db.test.create_index(["hello", "world"]) |
| 334 | db.test.create_index(["hello", ("world", DESCENDING)]) |
| 335 | db.test.create_index({"hello": 1}.items()) # type:ignore[arg-type] |
| 336 | |
| 337 | def test_drop_index(self): |
| 338 | db = self.db |
nothing calls this directly
no test coverage detected