|
33 | 33 | from test.asynchronous import AsyncIntegrationTest, AsyncPyMongoTestCase, async_client_context |
34 | 34 | from test.asynchronous.test_bulk import AsyncBulkTestBase |
35 | 35 | from test.asynchronous.utils import flaky |
36 | | -from test.asynchronous.utils_spec_runner import AsyncSpecRunner, AsyncSpecTestCreator |
37 | 36 | from threading import Thread |
38 | 37 | from typing import Any, Dict, Mapping, Optional |
39 | 38 |
|
|
55 | 54 | ) |
56 | 55 | from test.asynchronous.test_bulk import AsyncBulkTestBase |
57 | 56 | from test.asynchronous.unified_format import generate_test_classes |
58 | | -from test.asynchronous.utils_spec_runner import AsyncSpecRunner |
59 | 57 | from test.helpers_shared import ( |
60 | 58 | ALL_KMS_PROVIDERS, |
61 | 59 | AWS_CREDS, |
@@ -624,125 +622,6 @@ async def test_with_statement(self): |
624 | 622 | } |
625 | 623 |
|
626 | 624 |
|
627 | | -class AsyncTestSpec(AsyncSpecRunner): |
628 | | - @classmethod |
629 | | - @unittest.skipUnless(_HAVE_PYMONGOCRYPT, "pymongocrypt is not installed") |
630 | | - async def _setup_class(cls): |
631 | | - await super()._setup_class() |
632 | | - |
633 | | - def parse_auto_encrypt_opts(self, opts): |
634 | | - """Parse clientOptions.autoEncryptOpts.""" |
635 | | - opts = camel_to_snake_args(opts) |
636 | | - kms_providers = opts["kms_providers"] |
637 | | - if "aws" in kms_providers: |
638 | | - kms_providers["aws"] = AWS_CREDS |
639 | | - if not any(AWS_CREDS.values()): |
640 | | - self.skipTest("AWS environment credentials are not set") |
641 | | - if "awsTemporary" in kms_providers: |
642 | | - kms_providers["aws"] = AWS_TEMP_CREDS |
643 | | - del kms_providers["awsTemporary"] |
644 | | - if not any(AWS_TEMP_CREDS.values()): |
645 | | - self.skipTest("AWS Temp environment credentials are not set") |
646 | | - if "awsTemporaryNoSessionToken" in kms_providers: |
647 | | - kms_providers["aws"] = AWS_TEMP_NO_SESSION_CREDS |
648 | | - del kms_providers["awsTemporaryNoSessionToken"] |
649 | | - if not any(AWS_TEMP_NO_SESSION_CREDS.values()): |
650 | | - self.skipTest("AWS Temp environment credentials are not set") |
651 | | - if "azure" in kms_providers: |
652 | | - kms_providers["azure"] = AZURE_CREDS |
653 | | - if not any(AZURE_CREDS.values()): |
654 | | - self.skipTest("Azure environment credentials are not set") |
655 | | - if "gcp" in kms_providers: |
656 | | - kms_providers["gcp"] = GCP_CREDS |
657 | | - if not any(AZURE_CREDS.values()): |
658 | | - self.skipTest("GCP environment credentials are not set") |
659 | | - if "kmip" in kms_providers: |
660 | | - kms_providers["kmip"] = KMIP_CREDS |
661 | | - opts["kms_tls_options"] = DEFAULT_KMS_TLS |
662 | | - if "key_vault_namespace" not in opts: |
663 | | - opts["key_vault_namespace"] = "keyvault.datakeys" |
664 | | - if "extra_options" in opts: |
665 | | - opts.update(camel_to_snake_args(opts.pop("extra_options"))) |
666 | | - |
667 | | - opts = dict(opts) |
668 | | - return AutoEncryptionOpts(**opts) |
669 | | - |
670 | | - def parse_client_options(self, opts): |
671 | | - """Override clientOptions parsing to support autoEncryptOpts.""" |
672 | | - encrypt_opts = opts.pop("autoEncryptOpts", None) |
673 | | - if encrypt_opts: |
674 | | - opts["auto_encryption_opts"] = self.parse_auto_encrypt_opts(encrypt_opts) |
675 | | - |
676 | | - return super().parse_client_options(opts) |
677 | | - |
678 | | - def get_object_name(self, op): |
679 | | - """Default object is collection.""" |
680 | | - return op.get("object", "collection") |
681 | | - |
682 | | - def maybe_skip_scenario(self, test): |
683 | | - super().maybe_skip_scenario(test) |
684 | | - desc = test["description"].lower() |
685 | | - if ( |
686 | | - "timeoutms applied to listcollections to get collection schema" in desc |
687 | | - and sys.platform in ("win32", "darwin") |
688 | | - ): |
689 | | - self.skipTest("PYTHON-3706 flaky test on Windows/macOS") |
690 | | - if "type=symbol" in desc: |
691 | | - self.skipTest("PyMongo does not support the symbol type") |
692 | | - if "timeoutms applied to listcollections to get collection schema" in desc and not _IS_SYNC: |
693 | | - self.skipTest("PYTHON-4844 flaky test on async") |
694 | | - |
695 | | - async def setup_scenario(self, scenario_def): |
696 | | - """Override a test's setup.""" |
697 | | - key_vault_data = scenario_def["key_vault_data"] |
698 | | - encrypted_fields = scenario_def["encrypted_fields"] |
699 | | - json_schema = scenario_def["json_schema"] |
700 | | - data = scenario_def["data"] |
701 | | - coll = async_client_context.client.get_database("keyvault", codec_options=OPTS)["datakeys"] |
702 | | - await coll.delete_many({}) |
703 | | - if key_vault_data: |
704 | | - await coll.insert_many(key_vault_data) |
705 | | - |
706 | | - db_name = self.get_scenario_db_name(scenario_def) |
707 | | - coll_name = self.get_scenario_coll_name(scenario_def) |
708 | | - db = async_client_context.client.get_database(db_name, codec_options=OPTS) |
709 | | - await db.drop_collection(coll_name, encrypted_fields=encrypted_fields) |
710 | | - wc = WriteConcern(w="majority") |
711 | | - kwargs: Dict[str, Any] = {} |
712 | | - if json_schema: |
713 | | - kwargs["validator"] = {"$jsonSchema": json_schema} |
714 | | - kwargs["codec_options"] = OPTS |
715 | | - if not data: |
716 | | - kwargs["write_concern"] = wc |
717 | | - if encrypted_fields: |
718 | | - kwargs["encryptedFields"] = encrypted_fields |
719 | | - await db.create_collection(coll_name, **kwargs) |
720 | | - coll = db[coll_name] |
721 | | - if data: |
722 | | - # Load data. |
723 | | - await coll.with_options(write_concern=wc).insert_many(scenario_def["data"]) |
724 | | - |
725 | | - def allowable_errors(self, op): |
726 | | - """Override expected error classes.""" |
727 | | - errors = super().allowable_errors(op) |
728 | | - # An updateOne test expects encryption to error when no $ operator |
729 | | - # appears but pymongo raises a client side ValueError in this case. |
730 | | - if op["name"] == "updateOne": |
731 | | - errors += (ValueError,) |
732 | | - return errors |
733 | | - |
734 | | - |
735 | | -def create_test(scenario_def, test, name): |
736 | | - @async_client_context.require_test_commands |
737 | | - async def run_scenario(self): |
738 | | - await self.run_scenario(scenario_def, test) |
739 | | - |
740 | | - return run_scenario |
741 | | - |
742 | | - |
743 | | -test_creator = AsyncSpecTestCreator(create_test, AsyncTestSpec, os.path.join(SPEC_PATH, "legacy")) |
744 | | -test_creator.create_tests() |
745 | | - |
746 | 625 | if _HAVE_PYMONGOCRYPT: |
747 | 626 | globals().update( |
748 | 627 | generate_test_classes( |
|
0 commit comments