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

Method test_drop_collection

test/test_database.py:321–355  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

319 client.drop_database("test_collection_names_single_socket")
320
321 def test_drop_collection(self):
322 db = Database(self.client, "pymongo_test")
323
324 with self.assertRaises(TypeError):
325 db.drop_collection(5) # type: ignore[arg-type]
326 with self.assertRaises(TypeError):
327 db.drop_collection(None) # type: ignore[arg-type]
328
329 db.test.insert_one({"dummy": "object"})
330 self.assertIn("test", db.list_collection_names())
331 db.drop_collection("test")
332 self.assertNotIn("test", db.list_collection_names())
333
334 db.test.insert_one({"dummy": "object"})
335 self.assertIn("test", db.list_collection_names())
336 db.drop_collection("test")
337 self.assertNotIn("test", db.list_collection_names())
338
339 db.test.insert_one({"dummy": "object"})
340 self.assertIn("test", db.list_collection_names())
341 db.drop_collection(db.test)
342 self.assertNotIn("test", db.list_collection_names())
343
344 db.test.insert_one({"dummy": "object"})
345 self.assertIn("test", db.list_collection_names())
346 db.test.drop()
347 self.assertNotIn("test", db.list_collection_names())
348 db.test.drop()
349
350 db.drop_collection(db.test.doesnotexist)
351
352 if client_context.is_rs:
353 db_wc = Database(self.client, "pymongo_test", write_concern=IMPOSSIBLE_WRITE_CONCERN)
354 with self.assertRaises(WriteConcernError):
355 db_wc.drop_collection("test")
356
357 def test_validate_collection(self):
358 db = self.client.pymongo_test

Callers

nothing calls this directly

Calls 5

drop_collectionMethod · 0.95
list_collection_namesMethod · 0.95
DatabaseClass · 0.90
insert_oneMethod · 0.45
dropMethod · 0.45

Tested by

no test coverage detected