'Ensure that a sorted list field properly sorts values.'

def test_sorted_list_sorting(self):

    class Comment(EmbeddedDocument, ):
        order = IntField()
        content = StringField()
    class BlogPost(Document, ):
        content = StringField()
        comments = SortedListField(EmbeddedDocumentField(Comment), ordering='order')
        tags = SortedListField(StringField())
    BlogPost.drop_collection()
    post = BlogPost(content='Went    for    a    walk    today...')
    post.save()
    post.tags = ['leisure', 'fun']
    post.save()
    post.reload()
    self.assertEqual(post.tags, ['fun', 'leisure'])
    comment1 = Comment(content='Good    for    you', order=1)
    comment2 = Comment(content='Yay.', order=0)
    comments = [comment1, comment2]
    post.comments = comments
    post.save()
    post.reload()
    self.assertEqual(post.comments[0].content, comment2.content)
    self.assertEqual(post.comments[1].content, comment1.content)
    post.comments[0].order = 2
    post.save()
    post.reload()
    self.assertEqual(post.comments[0].content, comment1.content)
    self.assertEqual(post.comments[1].content, comment2.content)
