'Ensure an exception is raised when dereferencing an unknown
document.'

def test_reference_miss(self):

    class Foo(Document, ):
        pass
    class Bar(Document, ):
        ref = ReferenceField(Foo)
        generic_ref = GenericReferenceField()
    Foo.drop_collection()
    Bar.drop_collection()
    foo = Foo().save()
    bar = Bar(ref=foo, generic_ref=foo).save()
    foo.delete()
    bar = Bar.objects.get()
    self.assertRaises(DoesNotExist, getattr, bar, 'ref')
    self.assertRaises(DoesNotExist, getattr, bar, 'generic_ref')
    bar = Bar.objects.get()
    expected = foo.to_dbref()
    bar._fields['ref']._auto_dereference = False
    self.assertEqual(bar.ref, expected)
    bar._fields['generic_ref']._auto_dereference = False
    self.assertEqual(bar.generic_ref, {'_ref': expected, '_cls': 'Foo'})
