@@ -842,10 +842,16 @@ def test_modify_update(self):
842842
843843 @requires_mongodb_gte_26
844844 def test_modify_with_positional_push (self ):
845+ class Content (EmbeddedDocument ):
846+ keywords = ListField (StringField ())
847+
845848 class BlogPost (Document ):
846849 tags = ListField (StringField ())
850+ content = EmbeddedDocumentField (Content )
851+
852+ post = BlogPost .objects .create (
853+ tags = ['python' ], content = Content (keywords = ['ipsum' ]))
847854
848- post = BlogPost .objects .create (tags = ['python' ])
849855 self .assertEqual (post .tags , ['python' ])
850856 post .modify (push__tags__0 = ['code' , 'mongo' ])
851857 self .assertEqual (post .tags , ['code' , 'mongo' , 'python' ])
@@ -856,6 +862,16 @@ class BlogPost(Document):
856862 ['code' , 'mongo' , 'python' ]
857863 )
858864
865+ self .assertEqual (post .content .keywords , ['ipsum' ])
866+ post .modify (push__content__keywords__0 = ['lorem' ])
867+ self .assertEqual (post .content .keywords , ['lorem' , 'ipsum' ])
868+
869+ # Assert same order of the list items is maintained in the db
870+ self .assertEqual (
871+ BlogPost ._get_collection ().find_one ({'_id' : post .pk })['content' ]['keywords' ],
872+ ['lorem' , 'ipsum' ]
873+ )
874+
859875 def test_save (self ):
860876 """Ensure that a document may be saved in the database."""
861877
0 commit comments