From 12f80511cea39f908938737d36ba1561a6c66340 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 22 Apr 2025 14:26:27 -0500 Subject: [PATCH 1/4] PYTHON-5341 Fix handling of simple clients --- test/__init__.py | 8 ++++++++ test/asynchronous/__init__.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/test/__init__.py b/test/__init__.py index 7ae3432062..72d6729bd3 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1138,6 +1138,10 @@ def rs_or_single_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> Mo return self._async_mongo_client(h, p, **kwargs) def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: + client_options: dict = client_context.default_client_options.copy() + kwargs = kwargs.copy() + for key, value in client_options: + kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) else: @@ -1147,6 +1151,10 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli @classmethod def unmanaged_simple_client(cls, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: + client_options: dict = client_context.default_client_options.copy() + kwargs = kwargs.copy() + for key, value in client_options: + kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) else: diff --git a/test/asynchronous/__init__.py b/test/asynchronous/__init__.py index c57bf2a880..78015d6375 100644 --- a/test/asynchronous/__init__.py +++ b/test/asynchronous/__init__.py @@ -1154,6 +1154,10 @@ async def async_rs_or_single_client( return await self._async_mongo_client(h, p, **kwargs) def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> AsyncMongoClient: + client_options: dict = async_client_context.default_client_options.copy() + kwargs = kwargs.copy() + for key, value in client_options: + kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) else: @@ -1165,6 +1169,10 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> AsyncMon def unmanaged_simple_client( cls, h: Any = None, p: Any = None, **kwargs: Any ) -> AsyncMongoClient: + client_options: dict = async_client_context.default_client_options.copy() + kwargs = kwargs.copy() + for key, value in client_options: + kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) else: From 53369435000f7fb6c8cf122748bb3dae9c79c0f6 Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Tue, 22 Apr 2025 19:28:42 -0500 Subject: [PATCH 2/4] fix unpacking --- test/__init__.py | 4 ++-- test/asynchronous/__init__.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index 72d6729bd3..869c88d710 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1140,7 +1140,7 @@ def rs_or_single_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> Mo def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: client_options: dict = client_context.default_client_options.copy() kwargs = kwargs.copy() - for key, value in client_options: + for key, value in client_options.items(): kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) @@ -1153,7 +1153,7 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli def unmanaged_simple_client(cls, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: client_options: dict = client_context.default_client_options.copy() kwargs = kwargs.copy() - for key, value in client_options: + for key, value in client_options.items(): kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) diff --git a/test/asynchronous/__init__.py b/test/asynchronous/__init__.py index 78015d6375..ea5da0569e 100644 --- a/test/asynchronous/__init__.py +++ b/test/asynchronous/__init__.py @@ -1156,7 +1156,7 @@ async def async_rs_or_single_client( def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> AsyncMongoClient: client_options: dict = async_client_context.default_client_options.copy() kwargs = kwargs.copy() - for key, value in client_options: + for key, value in client_options.items(): kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) @@ -1171,7 +1171,7 @@ def unmanaged_simple_client( ) -> AsyncMongoClient: client_options: dict = async_client_context.default_client_options.copy() kwargs = kwargs.copy() - for key, value in client_options: + for key, value in client_options.items(): kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) From 4caa07fec3301d6ff729797a759f2f1f809bae4d Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 23 Apr 2025 08:31:11 -0500 Subject: [PATCH 3/4] fix api require version tests --- test/__init__.py | 8 -------- test/asynchronous/__init__.py | 8 -------- test/asynchronous/test_ssl.py | 4 ++++ test/test_ssl.py | 4 ++++ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/test/__init__.py b/test/__init__.py index 869c88d710..7ae3432062 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -1138,10 +1138,6 @@ def rs_or_single_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> Mo return self._async_mongo_client(h, p, **kwargs) def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: - client_options: dict = client_context.default_client_options.copy() - kwargs = kwargs.copy() - for key, value in client_options.items(): - kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) else: @@ -1151,10 +1147,6 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> MongoCli @classmethod def unmanaged_simple_client(cls, h: Any = None, p: Any = None, **kwargs: Any) -> MongoClient: - client_options: dict = client_context.default_client_options.copy() - kwargs = kwargs.copy() - for key, value in client_options.items(): - kwargs.setdefault(key, value) if not h and not p: client = MongoClient(**kwargs) else: diff --git a/test/asynchronous/__init__.py b/test/asynchronous/__init__.py index ea5da0569e..c57bf2a880 100644 --- a/test/asynchronous/__init__.py +++ b/test/asynchronous/__init__.py @@ -1154,10 +1154,6 @@ async def async_rs_or_single_client( return await self._async_mongo_client(h, p, **kwargs) def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> AsyncMongoClient: - client_options: dict = async_client_context.default_client_options.copy() - kwargs = kwargs.copy() - for key, value in client_options.items(): - kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) else: @@ -1169,10 +1165,6 @@ def simple_client(self, h: Any = None, p: Any = None, **kwargs: Any) -> AsyncMon def unmanaged_simple_client( cls, h: Any = None, p: Any = None, **kwargs: Any ) -> AsyncMongoClient: - client_options: dict = async_client_context.default_client_options.copy() - kwargs = kwargs.copy() - for key, value in client_options.items(): - kwargs.setdefault(key, value) if not h and not p: client = AsyncMongoClient(**kwargs) else: diff --git a/test/asynchronous/test_ssl.py b/test/asynchronous/test_ssl.py index d920b77ac2..5130b8a465 100644 --- a/test/asynchronous/test_ssl.py +++ b/test/asynchronous/test_ssl.py @@ -171,6 +171,7 @@ async def test_simple_ssl(self): await self.assertClientWorks(self.client) @async_client_context.require_tlsCertificateKeyFile + @async_client_context.require_no_api_version @ignore_deprecations async def test_tlsCertificateKeyFilePassword(self): # Expects the server to be running with server.pem and ca.pem @@ -376,6 +377,7 @@ async def test_cert_ssl_validation_hostname_matching(self): ) @async_client_context.require_tlsCertificateKeyFile + @async_client_context.require_no_api_version @ignore_deprecations async def test_tlsCRLFile_support(self): if not hasattr(ssl, "VERIFY_CRL_CHECK_LEAF") or _ssl.IS_PYOPENSSL: @@ -531,6 +533,7 @@ def test_wincertstore(self): @async_client_context.require_auth @async_client_context.require_tlsCertificateKeyFile + @async_client_context.require_no_api_version @ignore_deprecations async def test_mongodb_x509_auth(self): host, port = await async_client_context.host, await async_client_context.port @@ -640,6 +643,7 @@ async def test_mongodb_x509_auth(self): self.fail("Invalid certificate accepted.") @async_client_context.require_tlsCertificateKeyFile + @async_client_context.require_no_api_version @ignore_deprecations async def test_connect_with_ca_bundle(self): def remove(path): diff --git a/test/test_ssl.py b/test/test_ssl.py index a66fe21be5..0e0a4f348b 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -171,6 +171,7 @@ def test_simple_ssl(self): self.assertClientWorks(self.client) @client_context.require_tlsCertificateKeyFile + @client_context.require_no_api_version @ignore_deprecations def test_tlsCertificateKeyFilePassword(self): # Expects the server to be running with server.pem and ca.pem @@ -376,6 +377,7 @@ def test_cert_ssl_validation_hostname_matching(self): ) @client_context.require_tlsCertificateKeyFile + @client_context.require_no_api_version @ignore_deprecations def test_tlsCRLFile_support(self): if not hasattr(ssl, "VERIFY_CRL_CHECK_LEAF") or _ssl.IS_PYOPENSSL: @@ -531,6 +533,7 @@ def test_wincertstore(self): @client_context.require_auth @client_context.require_tlsCertificateKeyFile + @client_context.require_no_api_version @ignore_deprecations def test_mongodb_x509_auth(self): host, port = client_context.host, client_context.port @@ -640,6 +643,7 @@ def test_mongodb_x509_auth(self): self.fail("Invalid certificate accepted.") @client_context.require_tlsCertificateKeyFile + @client_context.require_no_api_version @ignore_deprecations def test_connect_with_ca_bundle(self): def remove(path): From 1063147a5cbda9ae2c88548d9b5b7c824815100c Mon Sep 17 00:00:00 2001 From: Steven Silvester Date: Wed, 23 Apr 2025 13:21:52 -0500 Subject: [PATCH 4/4] skip test on pypy --- test/asynchronous/test_ssl.py | 2 ++ test/test_ssl.py | 2 ++ 2 files changed, 4 insertions(+) diff --git a/test/asynchronous/test_ssl.py b/test/asynchronous/test_ssl.py index 5130b8a465..4d7566a61d 100644 --- a/test/asynchronous/test_ssl.py +++ b/test/asynchronous/test_ssl.py @@ -166,6 +166,8 @@ async def asyncTearDown(self): @async_client_context.require_tls async def test_simple_ssl(self): + if "PyPy" in sys.version: + self.skipTest("Test is flaky on PyPy") # Expects the server to be running with ssl and with # no --sslPEMKeyFile or with --sslWeakCertificateValidation await self.assertClientWorks(self.client) diff --git a/test/test_ssl.py b/test/test_ssl.py index 0e0a4f348b..7decc8203d 100644 --- a/test/test_ssl.py +++ b/test/test_ssl.py @@ -166,6 +166,8 @@ def tearDown(self): @client_context.require_tls def test_simple_ssl(self): + if "PyPy" in sys.version: + self.skipTest("Test is flaky on PyPy") # Expects the server to be running with ssl and with # no --sslPEMKeyFile or with --sslWeakCertificateValidation self.assertClientWorks(self.client)