support position in 'push' #1565

This commit is contained in:
Erdenezul Batmunkh
2017-06-15 06:08:40 +00:00
parent 2f1fe5468e
commit 6903eed4e7
2 changed files with 36 additions and 3 deletions

View File

@@ -1903,6 +1903,29 @@ class QuerySetTest(unittest.TestCase):
BlogPost.drop_collection()
def test_update_push_with_position(self):
"""Ensure that the 'push' update with position works properly.
"""
class BlogPost(Document):
slug = StringField()
tags = ListField(StringField())
BlogPost.drop_collection()
post = BlogPost(slug="test")
post.save()
BlogPost.objects.filter(id=post.id).update(push__tags="code")
BlogPost.objects.filter(id=post.id).update(push__tags__0=["mongodb", "python"])
post.reload()
self.assertEqual(post.tags[0], "mongodb")
self.assertEqual(post.tags[1], "python")
self.assertEqual(post.tags[2], "code")
BlogPost.objects.filter(id=post.id).update(set__tags__2="java")
post.reload()
self.assertEqual(post.tags[2], "java")
def test_update_push_and_pull_add_to_set(self):
"""Ensure that the 'pull' update operation works correctly.
"""