'Ensure that the correct subclasses are returned from a query
when using references / generic references'

def test_polymorphic_references(self):

    class Animal(Document, ):
        meta = {'allow_inheritance': True}
    class Fish(Animal, ):
        pass
    class Mammal(Animal, ):
        pass
    class Dog(Mammal, ):
        pass
    class Human(Mammal, ):
        pass
    class Zoo(Document, ):
        animals = ListField(ReferenceField(Animal))
    Zoo.drop_collection()
    Animal.drop_collection()
    Animal().save()
    Fish().save()
    Mammal().save()
    Dog().save()
    Human().save()
    zoo = Zoo(animals=Animal.objects)
    zoo.save()
    zoo.reload()
    classes = [a.__class__ for a in Zoo.objects.first().animals]
    self.assertEqual(classes, [Animal, Fish, Mammal, Dog, Human])
    Zoo.drop_collection()
    class Zoo(Document, ):
        animals = ListField(GenericReferenceField())
    zoo = Zoo(animals=Animal.objects)
    zoo.save()
    zoo.reload()
    classes = [a.__class__ for a in Zoo.objects.first().animals]
    self.assertEqual(classes, [Animal, Fish, Mammal, Dog, Human])
