'Regression test for #6886 (the related-object cache)'

def test_related_object_cache(self):

    p = Place.objects.get(name='Demon    Dogs')
    r = p.restaurant
    self.assertTrue((p.restaurant is r))
    del p._restaurant_cache
    self.assertFalse((p.restaurant is r))
    r2 = Restaurant.objects.get(pk=r.pk)
    p.restaurant = r2
    self.assertTrue((p.restaurant is r2))
    ug_bar = UndergroundBar.objects.create(place=p, serves_cocktails=False)
    ug_bar.place = None
    self.assertTrue((ug_bar.place is None))
    self.assertRaises(ValueError, setattr, p, 'restaurant', None)
    self.assertRaises(ValueError, setattr, p, 'restaurant', p)
    p = Place.objects.get(name='Demon    Dogs')
    r = Restaurant(place=p)
    self.assertTrue((r.place is p))
    p = Place()
    r = Restaurant(place=p)
    self.assertTrue((r.place is p))
    p = Place.objects.get(name='Demon    Dogs')
    r = Restaurant(place_id=p.id)
    self.assertFalse((r.place is p))
    self.assertEqual(r.place, p)
