(self)
| 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") |
nothing calls this directly
no test coverage detected