#NEWLINE# def test_generic_key_cross_database_protection( self ) : #NEWLINE# #INDENT# 'Operations that involve sharing generic key objects across databases raise an error' #NEWLINE# pro = Book . objects . create ( title = 'Pro Django' , published = datetime . date ( 2008 , 12 , 16 ) ) #NEWLINE# review1 = Review . objects . create ( source = 'Python Monthly' , content_object = pro ) #NEWLINE# dive = Book . objects . using ( 'other' ) . create ( title = 'Dive into Python' , published = datetime . date ( 2009 , 5 , 4 ) ) #NEWLINE# Review . objects . using ( 'other' ) . create ( source = 'Python Weekly' , content_object = dive ) #NEWLINE# with self . assertRaises ( ValueError ) : #NEWLINE# #INDENT# review1 . content_object = dive #NEWLINE# #UNINDENT# with self . assertRaises ( ValueError ) : #NEWLINE# #INDENT# with transaction . atomic ( using = 'other' ) : #NEWLINE# #INDENT# dive . reviews . add ( review1 ) #NEWLINE# #UNINDENT# #UNINDENT# review3 = Review ( source = 'Python Daily' ) #NEWLINE# self . assertEqual ( review3 . _state . db , None ) #NEWLINE# review3 . content_object = dive #NEWLINE# self . assertEqual ( dive . _state . db , 'other' ) #NEWLINE# self . assertEqual ( list ( Review . objects . using ( 'default' ) . filter ( object_id = pro . pk ) . values_list ( 'source' , flat = True ) ) , [ 'Python Monthly' ] ) #NEWLINE# self . assertEqual ( list ( Review . objects . using ( 'other' ) . filter ( object_id = dive . pk ) . values_list ( 'source' , flat = True ) ) , [ 'Python Weekly' ] ) #NEWLINE# review3 . save ( ) #NEWLINE# self . assertEqual ( list ( Review . objects . using ( 'default' ) . filter ( object_id = pro . pk ) . values_list ( 'source' , flat = True ) ) , [ 'Python Monthly' ] ) #NEWLINE# self . assertEqual ( list ( Review . objects . using ( 'other' ) . filter ( object_id = dive . pk ) . values_list ( 'source' , flat = True ) ) , [ 'Python Daily' , 'Python Weekly' ] )