'Ensure map/reduce is both mapping and reducing.'

def test_map_reduce(self):

    class BlogPost(Document, ):
        title = StringField()
        tags = ListField(StringField(), db_field='post-tag-list')
    BlogPost.drop_collection()
    BlogPost(title='Post    #1', tags=['music', 'film', 'print']).save()
    BlogPost(title='Post    #2', tags=['music', 'film']).save()
    BlogPost(title='Post    #3', tags=['film', 'photography']).save()
    map_f = '\n                                                function()    {\n                                                                this[~tags].forEach(function(tag)    {\n                                                                                emit(tag,    1);\n                                                                });\n                                                }\n                                '
    reduce_f = '\n                                                function(key,    values)    {\n                                                                var    total    =    0;\n                                                                for(var    i=0;    i<values.length;    i++)    {\n                                                                                total    +=    values[i];\n                                                                }\n                                                                return    total;\n                                                }\n                                '
    results = BlogPost.objects.map_reduce(map_f, reduce_f, 'myresults')
    results = list(results)
    self.assertEqual(len(results), 4)
    music = list(filter((lambda r: (r.key == 'music')), results))[0]
    self.assertEqual(music.value, 2)
    film = list(filter((lambda r: (r.key == 'film')), results))[0]
    self.assertEqual(film.value, 3)
    BlogPost.drop_collection()
