Skip to content

Commit b809090

Browse files
committed
Fix tests (comment not available on the newly updated method before pymongo 4.1)
1 parent 61cd76a commit b809090

File tree

3 files changed

+24
-14
lines changed

3 files changed

+24
-14
lines changed

tests/document/test_instance.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,13 +1901,16 @@ class AggPerson(Document):
19011901

19021902
comment = "test_comment"
19031903

1904-
with db_ops_tracker() as q:
1905-
_ = AggPerson.objects().comment(comment).delete()
1906-
query_op = q.db.system.profile.find({"ns": "mongoenginetest.agg_person"})[0]
1907-
CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query"
1908-
assert "hint" not in query_op[CMD_QUERY_KEY]
1909-
assert query_op[CMD_QUERY_KEY]["comment"] == comment
1910-
assert "collation" not in query_op[CMD_QUERY_KEY]
1904+
if PYMONGO_VERSION >= (4, 1):
1905+
with db_ops_tracker() as q:
1906+
_ = AggPerson.objects().comment(comment).delete()
1907+
query_op = q.db.system.profile.find(
1908+
{"ns": "mongoenginetest.agg_person"}
1909+
)[0]
1910+
CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query"
1911+
assert "hint" not in query_op[CMD_QUERY_KEY]
1912+
assert query_op[CMD_QUERY_KEY]["comment"] == comment
1913+
assert "collation" not in query_op[CMD_QUERY_KEY]
19111914

19121915
with db_ops_tracker() as q:
19131916
_ = AggPerson.objects.hint(index_name).delete()

tests/fields/test_binary_field.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
MONGODB_36,
99
get_mongodb_version,
1010
)
11+
from mongoengine.pymongo_support import PYMONGO_VERSION
1112
from tests.utils import MongoDBTestCase, db_ops_tracker
1213

1314
BIN_VALUE = "\xa9\xf3\x8d(\xd7\x03\x84\xb4k[\x0f\xe3\xa2\x19\x85p[J\xa3\xd2>\xde\xe6\x87\xb1\x7f\xc6\xe6\xd9r\x18\xf5".encode(
@@ -169,13 +170,16 @@ class AggPerson(Document):
169170

170171
comment = "test_comment"
171172

172-
with db_ops_tracker() as q:
173-
_ = AggPerson.objects.comment(comment).update_one(name="something")
174-
query_op = q.db.system.profile.find({"ns": "mongoenginetest.agg_person"})[0]
175-
CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query"
176-
assert "hint" not in query_op[CMD_QUERY_KEY]
177-
assert query_op[CMD_QUERY_KEY]["comment"] == comment
178-
assert "collation" not in query_op[CMD_QUERY_KEY]
173+
if PYMONGO_VERSION >= (4, 1):
174+
with db_ops_tracker() as q:
175+
_ = AggPerson.objects.comment(comment).update_one(name="something")
176+
query_op = q.db.system.profile.find(
177+
{"ns": "mongoenginetest.agg_person"}
178+
)[0]
179+
CMD_QUERY_KEY = "command" if mongo_ver >= MONGODB_36 else "query"
180+
assert "hint" not in query_op[CMD_QUERY_KEY]
181+
assert query_op[CMD_QUERY_KEY]["comment"] == comment
182+
assert "collation" not in query_op[CMD_QUERY_KEY]
179183

180184
with db_ops_tracker() as q:
181185
_ = AggPerson.objects.hint(index_name).update_one(name="something")

tests/utils.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@
22
import operator
33
import unittest
44

5+
import pymongo
56
import pytest
67

78
from mongoengine import connect
89
from mongoengine.connection import disconnect_all, get_db
910
from mongoengine.context_managers import query_counter
1011
from mongoengine.mongodb_support import get_mongodb_version
1112

13+
PYMONGO_VERSION = tuple(pymongo.version_tuple[:2])
14+
1215
MONGO_TEST_DB = "mongoenginetest" # standard name for the test database
1316

1417

0 commit comments

Comments
 (0)