Skip to content

Commit a362ddd

Browse files
committed
fix tests
1 parent 1fcbad8 commit a362ddd

4 files changed

Lines changed: 29 additions & 21 deletions

File tree

.github/workflows/github-actions.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ env:
1717
MONGODB_5_0: "5.0.31"
1818
MONGODB_6_0: "6.0.22"
1919
MONGODB_7_0: "7.0.19"
20-
MONGODB_8_0: "8.0.9"
2120

2221
PYMONGO_3_4: 3.4
2322
PYMONGO_3_6: 3.6

README.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ an `API reference <https://mongoengine-odm.readthedocs.io/apireference.html>`_.
3535

3636
Supported MongoDB Versions
3737
==========================
38-
MongoEngine is currently tested against MongoDB v4.4, v5.0, v6.0, v7.0 and
39-
v8.0. Future versions should be supported as well, but aren't actively tested
38+
MongoEngine is currently tested against MongoDB v4.4, v5.0, v6.0 and
39+
v7.0. Future versions should be supported as well, but aren't actively tested
4040
at the moment. Make sure to open an issue or submit a pull request if you
4141
experience any problems with a more recent MongoDB versions.
4242

mongoengine/connection.py

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -136,16 +136,22 @@ def _get_connection_settings(
136136
if uri_dict.get(param):
137137
conn_settings[param] = uri_dict[param]
138138

139-
uri_options = uri_dict[
140-
"options"
141-
] # uri_options is a _CaseInsensitiveDictionary
142-
if "replicaset" in uri_options:
143-
conn_settings["replicaSet"] = uri_options["replicaset"]
144-
if "authsource" in uri_options:
145-
conn_settings["authentication_source"] = uri_options["authsource"]
146-
if "authmechanism" in uri_options:
147-
conn_settings["authentication_mechanism"] = uri_options["authmechanism"]
148-
if "readpreference" in uri_options:
139+
uri_options = uri_dict["options"]
140+
normalized_uri_options = {
141+
key.lower(): value for key, value in uri_options.items()
142+
}
143+
144+
if "replicaset" in normalized_uri_options:
145+
conn_settings["replicaSet"] = normalized_uri_options["replicaset"]
146+
if "authsource" in normalized_uri_options:
147+
conn_settings["authentication_source"] = normalized_uri_options[
148+
"authsource"
149+
]
150+
if "authmechanism" in normalized_uri_options:
151+
conn_settings["authentication_mechanism"] = normalized_uri_options[
152+
"authmechanism"
153+
]
154+
if "readpreference" in normalized_uri_options:
149155
read_preferences = (
150156
ReadPreference.NEAREST,
151157
ReadPreference.PRIMARY,
@@ -159,7 +165,7 @@ def _get_connection_settings(
159165
# int (e.g. 3).
160166
# TODO simplify the code below once we drop support for
161167
# PyMongo v3.4.
162-
read_pf_mode = uri_options["readpreference"]
168+
read_pf_mode = normalized_uri_options["readpreference"]
163169
if isinstance(read_pf_mode, str):
164170
read_pf_mode = read_pf_mode.lower()
165171
for preference in read_preferences:
@@ -170,23 +176,23 @@ def _get_connection_settings(
170176
ReadPrefClass = preference.__class__
171177
break
172178

173-
if "readpreferencetags" in uri_options:
179+
if "readpreferencetags" in normalized_uri_options:
174180
conn_settings["read_preference"] = ReadPrefClass(
175-
tag_sets=uri_options["readpreferencetags"]
181+
tag_sets=normalized_uri_options["readpreferencetags"]
176182
)
177183
else:
178184
conn_settings["read_preference"] = ReadPrefClass()
179185

180-
if "authmechanismproperties" in uri_options:
181-
conn_settings["authmechanismproperties"] = uri_options[
186+
if "authmechanismproperties" in normalized_uri_options:
187+
conn_settings["authmechanismproperties"] = normalized_uri_options[
182188
"authmechanismproperties"
183189
]
184-
if "uuidrepresentation" in uri_options:
190+
if "uuidrepresentation" in normalized_uri_options:
185191
REV_UUID_REPRESENTATIONS = {
186192
v: k for k, v in _UUID_REPRESENTATIONS.items()
187193
}
188194
conn_settings["uuidrepresentation"] = REV_UUID_REPRESENTATIONS[
189-
uri_options["uuidrepresentation"]
195+
normalized_uri_options["uuidrepresentation"]
190196
]
191197
else:
192198
resolved_hosts.append(entity)

tests/test_connection.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,10 @@ def test_multiple_connection_settings(self):
653653
mongo_connections["t1"].server_info()
654654
mongo_connections["t2"].server_info()
655655
assert mongo_connections["t1"].address[0] == "localhost"
656-
assert mongo_connections["t2"].address[0] == "127.0.0.1"
656+
assert mongoengine.connection._connection_settings["t2"]["host"] == [
657+
"127.0.0.1"
658+
]
659+
assert mongo_connections["t1"] is not mongo_connections["t2"]
657660

658661
def test_connect_2_databases_uses_same_client_if_only_dbname_differs(self):
659662
c1 = connect(alias="testdb1", db="testdb1")

0 commit comments

Comments
 (0)