(self)
| 242 | self.assertNotIn("listCollections", listener.started_command_names()) |
| 243 | |
| 244 | def test_list_collections(self): |
| 245 | self.client.drop_database("pymongo_test") |
| 246 | db = Database(self.client, "pymongo_test") |
| 247 | db.test.insert_one({"dummy": "object"}) |
| 248 | db.test.mike.insert_one({"dummy": "object"}) |
| 249 | |
| 250 | results = db.list_collections() |
| 251 | colls = [result["name"] for result in results] |
| 252 | |
| 253 | # All the collections present. |
| 254 | self.assertIn("test", colls) |
| 255 | self.assertIn("test.mike", colls) |
| 256 | |
| 257 | # No collection containing a '$'. |
| 258 | for coll in colls: |
| 259 | self.assertNotIn("$", coll) |
| 260 | |
| 261 | # Duplicate check. |
| 262 | coll_cnt: dict = {} |
| 263 | for coll in colls: |
| 264 | try: |
| 265 | # Found duplicate. |
| 266 | coll_cnt[coll] += 1 |
| 267 | self.fail("Found duplicate") |
| 268 | except KeyError: |
| 269 | coll_cnt[coll] = 1 |
| 270 | coll_cnt: dict = {} |
| 271 | |
| 272 | # Check if there are any collections which don't exist. |
| 273 | self.assertLessEqual(set(colls), {"test", "test.mike", "system.indexes"}) |
| 274 | |
| 275 | colls = (db.list_collections(filter={"name": {"$regex": "^test$"}})).to_list() |
| 276 | self.assertEqual(1, len(colls)) |
| 277 | |
| 278 | colls = (db.list_collections(filter={"name": {"$regex": "^test.mike$"}})).to_list() |
| 279 | self.assertEqual(1, len(colls)) |
| 280 | |
| 281 | db.drop_collection("test") |
| 282 | |
| 283 | db.create_collection("test", capped=True, size=4096) |
| 284 | results = db.list_collections(filter={"options.capped": True}) |
| 285 | colls = [result["name"] for result in results] |
| 286 | |
| 287 | # Checking only capped collections are present |
| 288 | self.assertIn("test", colls) |
| 289 | self.assertNotIn("test.mike", colls) |
| 290 | |
| 291 | # No collection containing a '$'. |
| 292 | for coll in colls: |
| 293 | self.assertNotIn("$", coll) |
| 294 | |
| 295 | # Duplicate check. |
| 296 | coll_cnt = {} |
| 297 | for coll in colls: |
| 298 | try: |
| 299 | # Found duplicate. |
| 300 | coll_cnt[coll] += 1 |
| 301 | self.fail("Found duplicate") |
nothing calls this directly
no test coverage detected