Skip to content

Commit 059ad14

Browse files
committed
Fix recently modified tx tests
1 parent fe9e42a commit 059ad14

File tree

3 files changed

+25
-8
lines changed

3 files changed

+25
-8
lines changed

mongoengine/queryset/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ def get(self, *q_objs, **query):
282282
except StopIteration:
283283
return result
284284

285-
# If we were able to retrieve the 2nd doc, raise the MultipleObjectsReturned exception.
285+
# If we were able to retrieve a 2nd doc, raise the MultipleObjectsReturned exception.
286286
raise queryset._document.MultipleObjectsReturned(
287287
"2 or more items returned, instead of 1"
288288
)

tests/test_connection.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -633,22 +633,38 @@ def test_read_preference_from_parse(self):
633633
assert conn.read_preference == ReadPreference.SECONDARY_PREFERRED
634634

635635
def test_multiple_connection_settings(self):
636-
connect("mongoenginetest", alias="t1", host="localhost")
637-
638-
connect("mongoenginetest2", alias="t2", host="127.0.0.1")
636+
connect(
637+
"mongoenginetest",
638+
alias="t1",
639+
host="localhost",
640+
read_preference=ReadPreference.PRIMARY,
641+
)
642+
connect(
643+
"mongoenginetest2",
644+
alias="t2",
645+
host="127.0.0.1",
646+
read_preference=ReadPreference.PRIMARY_PREFERRED,
647+
)
639648

640649
mongo_connections = mongoengine.connection._connections
641650
assert len(mongo_connections.items()) == 2
642651
assert "t1" in mongo_connections.keys()
643652
assert "t2" in mongo_connections.keys()
644653

645-
# Handle PyMongo 3+ Async Connection
654+
# Handle PyMongo 3+ Async Connection (lazily established)
646655
# Ensure we are connected, throws ServerSelectionTimeoutError otherwise.
647656
# Purposely not catching exception to fail test if thrown.
648657
mongo_connections["t1"].server_info()
649658
mongo_connections["t2"].server_info()
659+
650660
assert mongo_connections["t1"].address[0] == "localhost"
651-
assert mongo_connections["t2"].address[0] == "127.0.0.1"
661+
assert (
662+
mongo_connections["t2"].address[0] == "localhost"
663+
) # weird but we have this with replicaset
664+
assert mongo_connections["t1"].read_preference == ReadPreference.PRIMARY
665+
assert (
666+
mongo_connections["t2"].read_preference == ReadPreference.PRIMARY_PREFERRED
667+
)
652668
assert mongo_connections["t1"] is not mongo_connections["t2"]
653669

654670
def test_connect_2_databases_uses_same_client_if_only_dbname_differs(self):

tests/test_context_managers.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class A(Document):
550550
assert A.objects.get(id=a_doc.id).name == "b"
551551
raise TestRollbackError()
552552

553-
assert A.objects.count() == 0
553+
assert A.objects.count() == 1
554554
assert A.objects.get(id=a_doc.id).name == "a"
555555

556556
@requires_mongodb_gte_40
@@ -793,7 +793,7 @@ def test_thread_safety_of_transactions(self):
793793
of value 0 - 9.
794794
795795
We then spin up 10 threads and attempt to update a target
796-
record by multiplying it's integer value by 10. Then, if
796+
record by multiplying its integer value by 10. Then, if
797797
the target record is even, throw an exception, which
798798
should then roll the transaction back. The odd rows always
799799
succeed.
@@ -809,6 +809,7 @@ def test_thread_safety_of_transactions(self):
809809
class A(Document):
810810
i = IntField()
811811

812+
A.drop_collection()
812813
# Ensure the collection is created
813814
A.objects.create(i=0)
814815

0 commit comments

Comments
 (0)