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

Class UnifiedSpecTestMixinV1

test/unified_format.py:466–1524  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Calls 1

from_stringMethod · 0.80