Mixin class to run test cases from test specification files. Assumes that tests conform to the `unified test format `_. Specification of the test suite being currently run is availa
| 465 | |
| 466 | |
| 467 | class UnifiedSpecTestMixinV1(AsyncIntegrationTest): |
| 468 | """Mixin class to run test cases from test specification files. |
| 469 | |
| 470 | Assumes that tests conform to the `unified test format |
| 471 | <https://github.com/mongodb/specifications/blob/master/source/unified-test-format/unified-test-format.md>`_. |
| 472 | |
| 473 | Specification of the test suite being currently run is available as |
| 474 | a class attribute ``TEST_SPEC``. |
| 475 | """ |
| 476 | |
| 477 | SCHEMA_VERSION = Version.from_string("1.26") |
| 478 | RUN_ON_LOAD_BALANCER = True |
| 479 | TEST_SPEC: Any |
| 480 | TEST_PATH = "" # This gets filled in by generate_test_classes |
| 481 | mongos_clients: list[AsyncMongoClient] = [] |
| 482 | |
| 483 | @staticmethod |
| 484 | async def should_run_on(run_on_spec): |
| 485 | if not run_on_spec: |
| 486 | # Always run these tests. |
| 487 | return True |
| 488 | |
| 489 | for req in run_on_spec: |
| 490 | if await is_run_on_requirement_satisfied(req): |
| 491 | return True |
| 492 | return False |
| 493 | |
| 494 | async def insert_initial_data(self, initial_data): |
| 495 | for i, collection_data in enumerate(initial_data): |
| 496 | coll_name = collection_data["collectionName"] |
| 497 | db_name = collection_data["databaseName"] |
| 498 | opts = collection_data.get("createOptions", {}) |
| 499 | documents = collection_data["documents"] |
| 500 | |
| 501 | # Setup the collection with as few majority writes as possible. |
| 502 | db = self.client[db_name] |
| 503 | await db.drop_collection(coll_name) |
| 504 | # Only use majority wc only on the final write. |
| 505 | if i == len(initial_data) - 1: |
| 506 | wc = WriteConcern(w="majority") |
| 507 | else: |
| 508 | wc = WriteConcern(w=1) |
| 509 | |
| 510 | # Remove any encryption collections associated with the collection. |
| 511 | collections = await db.list_collection_names() |
| 512 | for collection in collections: |
| 513 | if collection in [f"enxcol_.{coll_name}.esc", f"enxcol_.{coll_name}.ecoc"]: |
| 514 | await db.drop_collection(collection) |
| 515 | |
| 516 | if documents: |
| 517 | if opts: |
| 518 | await db.create_collection(coll_name, **opts) |
| 519 | await db.get_collection(coll_name, write_concern=wc).insert_many(documents) |
| 520 | else: |
| 521 | # Ensure collection exists |
| 522 | await db.create_collection(coll_name, write_concern=wc, **opts) |
| 523 | |
| 524 | @classmethod |