Skip to content

Commit b479bb7

Browse files
committed
Fix tests for supporting Mongo4.4 for some reason results comes sorted differently in map reduce when no sort is specified
1 parent 8ef7719 commit b479bb7

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

tests/queryset/test_queryset.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2666,6 +2666,8 @@ class BlogPost(Document):
26662666
title = StringField(primary_key=True)
26672667
tags = ListField(StringField())
26682668

2669+
BlogPost.drop_collection()
2670+
26692671
post1 = BlogPost(title="Post #1", tags=["mongodb", "mongoengine"])
26702672
post2 = BlogPost(title="Post #2", tags=["django", "mongodb"])
26712673
post3 = BlogPost(title="Post #3", tags=["hitchcock films"])
@@ -2694,20 +2696,22 @@ class BlogPost(Document):
26942696
}
26952697
"""
26962698

2697-
results = BlogPost.objects.map_reduce(map_f, reduce_f, "myresults")
2699+
results = BlogPost.objects.order_by("_id").map_reduce(
2700+
map_f, reduce_f, "myresults2"
2701+
)
26982702
results = list(results)
26992703

2700-
assert results[0].object == post1
2701-
assert results[1].object == post2
2702-
assert results[2].object == post3
2704+
assert len(results) == 3
2705+
assert results[0].object.id == post1.id
2706+
assert results[1].object.id == post2.id
2707+
assert results[2].object.id == post3.id
27032708

27042709
BlogPost.drop_collection()
27052710

27062711
def test_map_reduce_custom_output(self):
27072712
"""
27082713
Test map/reduce custom output
27092714
"""
2710-
register_connection("test2", "mongoenginetest2")
27112715

27122716
class Family(Document):
27132717
id = IntField(primary_key=True)
@@ -2780,6 +2784,7 @@ class Person(Document):
27802784
family.persons.push(person);
27812785
family.totalAge += person.age;
27822786
});
2787+
family.persons.sort((a, b) => (a.age > b.age))
27832788
}
27842789
});
27852790
@@ -2808,10 +2813,10 @@ class Person(Document):
28082813
"_id": 1,
28092814
"value": {
28102815
"persons": [
2816+
{"age": 17, "name": "Tayza Mariana"},
28112817
{"age": 21, "name": "Wilson Jr"},
2812-
{"age": 45, "name": "Wilson Father"},
28132818
{"age": 40, "name": "Eliana Costa"},
2814-
{"age": 17, "name": "Tayza Mariana"},
2819+
{"age": 45, "name": "Wilson Father"},
28152820
],
28162821
"totalAge": 123,
28172822
},
@@ -2821,9 +2826,9 @@ class Person(Document):
28212826
"_id": 2,
28222827
"value": {
28232828
"persons": [
2829+
{"age": 10, "name": "Igor Gabriel"},
28242830
{"age": 16, "name": "Isabella Luanna"},
28252831
{"age": 36, "name": "Sandra Mara"},
2826-
{"age": 10, "name": "Igor Gabriel"},
28272832
],
28282833
"totalAge": 62,
28292834
},
@@ -2833,8 +2838,8 @@ class Person(Document):
28332838
"_id": 3,
28342839
"value": {
28352840
"persons": [
2836-
{"age": 30, "name": "Arthur WA"},
28372841
{"age": 25, "name": "Paula Leonel"},
2842+
{"age": 30, "name": "Arthur WA"},
28382843
],
28392844
"totalAge": 55,
28402845
},

0 commit comments

Comments
 (0)