'Operations that involve sharing FK objects across databases raise an error'

def test_foreign_key_cross_database_protection(self):

    pro = Book.objects.create(title='Pro    Django', published=datetime.date(2008, 12, 16))
    marty = Person.objects.create(name='Marty    Alchin')
    dive = Book.objects.using('other').create(title='Dive    into    Python', published=datetime.date(2009, 5, 4))
    mark = Person.objects.using('other').create(name='Mark    Pilgrim')
    try:
        dive.editor = marty
        self.fail("Shouldn't    be    able    to    assign    across    databases")
    except ValueError:
        pass
    try:
        marty.edited = [pro, dive]
        self.fail("Shouldn't    be    able    to    assign    across    databases")
    except ValueError:
        pass
    try:
        marty.edited.add(dive)
        self.fail("Shouldn't    be    able    to    assign    across    databases")
    except ValueError:
        pass
    chris = Person(name='Chris    Mills')
    html5 = Book(title='Dive    into    HTML5', published=datetime.date(2010, 3, 15))
    self.assertEqual(chris._state.db, None)
    self.assertEqual(html5._state.db, None)
    dive.editor = chris
    html5.editor = mark
    self.assertEqual(chris._state.db, 'other')
    self.assertEqual(html5._state.db, 'other')
    self.assertEqual(list(Person.objects.using('other').values_list('name', flat=True)), [u'Mark    Pilgrim'])
    self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)), [u'Dive    into    Python'])
    chris.save()
    html5.save()
    self.assertEqual(list(Person.objects.using('default').values_list('name', flat=True)), [u'Marty    Alchin'])
    self.assertEqual(list(Person.objects.using('other').values_list('name', flat=True)), [u'Chris    Mills', u'Mark    Pilgrim'])
    self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)), [u'Pro    Django'])
    self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)), [u'Dive    into    HTML5', u'Dive    into    Python'])
    water = Book(title='Dive    into    Water', published=datetime.date(2001, 1, 1), editor=mark)
    self.assertEqual(water._state.db, 'other')
    self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)), [u'Pro    Django'])
    self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)), [u'Dive    into    HTML5', u'Dive    into    Python'])
    water.save()
    self.assertEqual(list(Book.objects.using('default').values_list('title', flat=True)), [u'Pro    Django'])
    self.assertEqual(list(Book.objects.using('other').values_list('title', flat=True)), [u'Dive    into    HTML5', u'Dive    into    Python', u'Dive    into    Water'])
