Skip to content

Commit

Permalink
Fix for tests (tx with mongodb <= 4.2 requires collection to be creat…
Browse files Browse the repository at this point in the history
…ed outside tx)
  • Loading branch information
bagerard committed Sep 4, 2024
1 parent c217cae commit 8feba86
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM mongo:5
FROM mongo:4.0

COPY ./entrypoint.sh entrypoint.sh
RUN chmod u+x entrypoint.sh
Expand Down
2 changes: 1 addition & 1 deletion docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Changelog
Development
===========
- (Fill this out as you fix issues and develop your features).
- Add support for transaction through run_in_transaction #2569
- Add support for transaction through run_in_transaction (kudos to juannyG for this) #2569

Changes in 0.29.0
=================
Expand Down
19 changes: 7 additions & 12 deletions tests/test_context_managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,6 @@ def test_query_counter_ignores_particular_queries(self):

@requires_mongodb_gte_40
def test_updating_a_document_within_a_transaction(self):
connect("mongoenginetest")

class A(Document):
name = StringField()

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

@requires_mongodb_gte_40
def test_updating_a_document_within_a_transaction_that_fails(self):
connect("mongoenginetest")

class A(Document):
name = StringField()

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

@requires_mongodb_gte_40
def test_creating_a_document_within_a_transaction(self):
connect("mongoenginetest")

class A(Document):
name = StringField()

A.drop_collection()

# ensure collection is created (needed for transaction with MongoDB <= 4.2)
A.objects.create(name="test")
A.objects.delete()

with run_in_transaction():
a_doc = A.objects.create(name="a")
another_doc = A(name="b").save()
Expand All @@ -578,12 +577,14 @@ class A(Document):

@requires_mongodb_gte_40
def test_creating_a_document_within_a_transaction_that_fails(self):
connect("mongoenginetest")

class A(Document):
name = StringField()

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

with pytest.raises(TestRollbackError):
with run_in_transaction():
Expand Down Expand Up @@ -695,8 +696,6 @@ class B(Document):

@requires_mongodb_gte_40
def test_exception_in_child_of_a_nested_transaction_rolls_parent_back(self):
connect("mongoenginetest")

class A(Document):
name = StringField()

Expand Down Expand Up @@ -731,8 +730,6 @@ class B(Document):
def test_exception_in_parent_of_nested_transaction_after_child_completed_only_rolls_parent_back(
self,
):
connect("mongoenginetest")

class A(Document):
name = StringField()

Expand Down Expand Up @@ -772,7 +769,6 @@ def run_tx():

@requires_mongodb_gte_40
def test_nested_transactions_create_and_release_sessions_accordingly(self):
connect("mongoenginetest")
with run_in_transaction():
s1 = _get_session()
with run_in_transaction():
Expand Down Expand Up @@ -808,7 +804,6 @@ def test_thread_safety_of_transactions(self):
0 + 10 + 2 + 30 + 4 + 50 + 6 + 70 + 8 + 90 = 270
"""
connect("mongoenginetest")

class A(Document):
i = IntField(unique=True)
Expand Down

0 comments on commit 8feba86

Please sign in to comment.