'Generic Key operations can span databases if they share a source'

def test_generic_key_cross_database_protection(self):

    pro = Book.objects.using(u'default').create(title=u'Pro    Django', published=datetime.date(2008, 12, 16))
    review1 = Review.objects.using(u'default').create(source=u'Python    Monthly', content_object=pro)
    dive = Book.objects.using(u'other').create(title=u'Dive    into    Python', published=datetime.date(2009, 5, 4))
    review2 = Review.objects.using(u'other').create(source=u'Python    Weekly', content_object=dive)
    try:
        review1.content_object = dive
    except ValueError:
        self.fail(u'Assignment    across    master/slave    databases    with    a    common    source    should    be    ok')
    self.assertEqual(pro._state.db, u'default')
    self.assertEqual(review1._state.db, u'default')
    self.assertEqual(dive._state.db, u'other')
    self.assertEqual(review2._state.db, u'other')
    dive.save()
    self.assertEqual(review1._state.db, u'default')
    self.assertEqual(dive._state.db, u'default')
    try:
        Book.objects.using(u'default').get(title=u'Dive    into    Python').delete()
    except Book.DoesNotExist:
        self.fail(u'Source    database    should    have    a    copy    of    saved    object')
    dive = Book.objects.using(u'other').get(title=u'Dive    into    Python')
    self.assertEqual(dive._state.db, u'other')
    try:
        dive.reviews.add(review1)
    except ValueError:
        self.fail(u'Assignment    across    master/slave    databases    with    a    common    source    should    be    ok')
    self.assertEqual(pro._state.db, u'default')
    self.assertEqual(review1._state.db, u'default')
    self.assertEqual(dive._state.db, u'other')
    self.assertEqual(review2._state.db, u'other')
    dive.save()
    self.assertEqual(dive._state.db, u'default')
    try:
        Book.objects.using(u'default').get(title=u'Dive    into    Python').delete()
    except Book.DoesNotExist:
        self.fail(u'Source    database    should    have    a    copy    of    saved    object')
    review3 = Review(source=u'Python    Daily')
    self.assertEqual(review3._state.db, None)
    review3.content_object = dive
    self.assertEqual(review3._state.db, u'default')
    dive = Book.objects.using(u'other').get(title=u'Dive    into    Python')
    nyt = dive.reviews.create(source=u'New    York    Times', content_object=dive)
    self.assertEqual(nyt._state.db, u'default')
