Skip to content

Commit 8feba86

Browse files
committed
Fix for tests (tx with mongodb <= 4.2 requires collection to be created outside tx)
1 parent c217cae commit 8feba86

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM mongo:5
1+
FROM mongo:4.0
22

33
COPY ./entrypoint.sh entrypoint.sh
44
RUN chmod u+x entrypoint.sh

docs/changelog.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Changelog
77
Development
88
===========
99
- (Fill this out as you fix issues and develop your features).
10-
- Add support for transaction through run_in_transaction #2569
10+
- Add support for transaction through run_in_transaction (kudos to juannyG for this) #2569
1111

1212
Changes in 0.29.0
1313
=================

tests/test_context_managers.py

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,6 @@ def test_query_counter_ignores_particular_queries(self):
519519

520520
@requires_mongodb_gte_40
521521
def test_updating_a_document_within_a_transaction(self):
522-
connect("mongoenginetest")
523-
524522
class A(Document):
525523
name = StringField()
526524

@@ -538,8 +536,6 @@ class A(Document):
538536

539537
@requires_mongodb_gte_40
540538
def test_updating_a_document_within_a_transaction_that_fails(self):
541-
connect("mongoenginetest")
542-
543539
class A(Document):
544540
name = StringField()
545541

@@ -558,13 +554,16 @@ class A(Document):
558554

559555
@requires_mongodb_gte_40
560556
def test_creating_a_document_within_a_transaction(self):
561-
connect("mongoenginetest")
562557

563558
class A(Document):
564559
name = StringField()
565560

566561
A.drop_collection()
567562

563+
# ensure collection is created (needed for transaction with MongoDB <= 4.2)
564+
A.objects.create(name="test")
565+
A.objects.delete()
566+
568567
with run_in_transaction():
569568
a_doc = A.objects.create(name="a")
570569
another_doc = A(name="b").save()
@@ -578,12 +577,14 @@ class A(Document):
578577

579578
@requires_mongodb_gte_40
580579
def test_creating_a_document_within_a_transaction_that_fails(self):
581-
connect("mongoenginetest")
582580

583581
class A(Document):
584582
name = StringField()
585583

586584
A.drop_collection()
585+
# ensure collection is created (needed for transaction with MongoDB <= 4.2)
586+
A.objects.create(name="test")
587+
A.objects.delete()
587588

588589
with pytest.raises(TestRollbackError):
589590
with run_in_transaction():
@@ -695,8 +696,6 @@ class B(Document):
695696

696697
@requires_mongodb_gte_40
697698
def test_exception_in_child_of_a_nested_transaction_rolls_parent_back(self):
698-
connect("mongoenginetest")
699-
700699
class A(Document):
701700
name = StringField()
702701

@@ -731,8 +730,6 @@ class B(Document):
731730
def test_exception_in_parent_of_nested_transaction_after_child_completed_only_rolls_parent_back(
732731
self,
733732
):
734-
connect("mongoenginetest")
735-
736733
class A(Document):
737734
name = StringField()
738735

@@ -772,7 +769,6 @@ def run_tx():
772769

773770
@requires_mongodb_gte_40
774771
def test_nested_transactions_create_and_release_sessions_accordingly(self):
775-
connect("mongoenginetest")
776772
with run_in_transaction():
777773
s1 = _get_session()
778774
with run_in_transaction():
@@ -808,7 +804,6 @@ def test_thread_safety_of_transactions(self):
808804
809805
0 + 10 + 2 + 30 + 4 + 50 + 6 + 70 + 8 + 90 = 270
810806
"""
811-
connect("mongoenginetest")
812807

813808
class A(Document):
814809
i = IntField(unique=True)

0 commit comments

Comments
 (0)