From 37762abc6f701c4a54f1868a095830ee0e8d1994 Mon Sep 17 00:00:00 2001 From: Elijah Frederickson Date: Wed, 18 Sep 2024 20:32:47 -0400 Subject: [PATCH] The WebIDE will only take you so far --- tests/queryset/test_queryset_aggregation.py | 9 +++++---- tests/test_connection.py | 7 ++++++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/tests/queryset/test_queryset_aggregation.py b/tests/queryset/test_queryset_aggregation.py index f1d504c0b..ecfa0b6f3 100644 --- a/tests/queryset/test_queryset_aggregation.py +++ b/tests/queryset/test_queryset_aggregation.py @@ -19,10 +19,11 @@ class Bar(Document): bars = Bar.objects.read_preference( ReadPreference.SECONDARY_PREFERRED ).aggregate(pipeline) - assert ( - bars._CommandCursor__collection.read_preference - == ReadPreference.SECONDARY_PREFERRED - ) + if hasattr(bars, "_CommandCursor__collection"): + read_pref = bars._CommandCursor__collection.read_preference + else: # pymongo >= 4.9 + read_pref = bars._collection.read_preference + assert read_pref == ReadPreference.SECONDARY_PREFERRED def test_queryset_aggregation_framework(self): class Person(Document): diff --git a/tests/test_connection.py b/tests/test_connection.py index c88f87c93..5b47383b4 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -3,6 +3,8 @@ import uuid import pymongo +import pymongo.database +import pymongo.mongo_client import pytest from bson.tz_util import utc from pymongo import MongoClient, ReadPreference @@ -608,7 +610,10 @@ def test_connect_with_replicaset_via_kwargs(self): connection kwargs """ c = connect(replicaset="local-rs") - assert c._MongoClient__options.replica_set_name == "local-rs" + if hasattr(c, "_MongoClient__options"): + assert c._MongoClient__options.replica_set_name == "local-rs" + else: # pymongo >= 4.9 + assert c._options.replica_set_name == "local-rs" db = get_db() assert isinstance(db, pymongo.database.Database) assert db.name == "test"