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

Method test_create_collection

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

Source from the content-addressed store, hash-verified

146 )
147
148 def test_create_collection(self):
149 db = Database(self.client, "pymongo_test")
150
151 db.test.insert_one({"hello": "world"})
152 with self.assertRaises(CollectionInvalid):
153 db.create_collection("test")
154
155 db.drop_collection("test")
156
157 with self.assertRaises(TypeError):
158 db.create_collection(5) # type: ignore[arg-type]
159 with self.assertRaises(TypeError):
160 db.create_collection(None) # type: ignore[arg-type]
161 with self.assertRaises(InvalidName):
162 db.create_collection("coll..ection") # type: ignore[arg-type]
163
164 test = db.create_collection("test")
165 self.assertIn("test", db.list_collection_names())
166 test.insert_one({"hello": "world"})
167 self.assertEqual((db.test.find_one())["hello"], "world")
168
169 db.drop_collection("test.foo")
170 db.create_collection("test.foo")
171 self.assertIn("test.foo", db.list_collection_names())
172 with self.assertRaises(CollectionInvalid):
173 db.create_collection("test.foo")
174
175 def test_list_collection_names(self):
176 db = Database(self.client, "pymongo_test")

Callers

nothing calls this directly

Calls 6

create_collectionMethod · 0.95
drop_collectionMethod · 0.95
list_collection_namesMethod · 0.95
DatabaseClass · 0.90
insert_oneMethod · 0.45
find_oneMethod · 0.45

Tested by

no test coverage detected