'Operations that involve sharing generic key objects across databases raise an error'

def test_generic_key_cross_database_protection(self):

    pro = Book.objects.create(title='Pro    Django', published=datetime.date(2008, 12, 16))
    review1 = Review.objects.create(source='Python    Monthly', content_object=pro)
    dive = Book.objects.using('other').create(title='Dive    into    Python', published=datetime.date(2009, 5, 4))
    review2 = Review.objects.using('other').create(source='Python    Weekly', content_object=dive)
    try:
        review1.content_object = dive
        self.fail("Shouldn't    be    able    to    assign    across    databases")
    except ValueError:
        pass
    try:
        dive.reviews.add(review1)
        self.fail("Shouldn't    be    able    to    assign    across    databases")
    except ValueError:
        pass
    review3 = Review(source='Python    Daily')
    self.assertEqual(review3._state.db, None)
    review3.content_object = dive
    self.assertEqual(review3._state.db, 'other')
    self.assertEqual(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)), [u'Python    Monthly'])
    self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)), [u'Python    Weekly'])
    review3.save()
    self.assertEqual(list(Review.objects.using('default').filter(object_id=pro.pk).values_list('source', flat=True)), [u'Python    Monthly'])
    self.assertEqual(list(Review.objects.using('other').filter(object_id=dive.pk).values_list('source', flat=True)), [u'Python    Daily', u'Python    Weekly'])
