#NEWLINE# def test_get_or_create( self ) : #NEWLINE# #INDENT# p = Person . objects . create ( first_name = 'John' , last_name = 'Lennon' , birthday = date ( 1940 , 10 , 9 ) ) #NEWLINE# ( p , created ) = Person . objects . get_or_create ( first_name = 'John' , last_name = 'Lennon' , defaults = { #NEWLINE# #INDENT# 'birthday' : date ( 1940 , 10 , 9 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertFalse ( created ) #NEWLINE# self . assertEqual ( Person . objects . count ( ) , 1 ) #NEWLINE# ( p , created ) = Person . objects . get_or_create ( first_name = 'George' , last_name = 'Harrison' , defaults = { #NEWLINE# #INDENT# 'birthday' : date ( 1943 , 2 , 25 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertTrue ( created ) #NEWLINE# self . assertEqual ( Person . objects . count ( ) , 2 ) #NEWLINE# ( p , created ) = Person . objects . get_or_create ( first_name = 'George' , last_name = 'Harrison' , defaults = { #NEWLINE# #INDENT# 'birthday' : date ( 1943 , 2 , 25 ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# self . assertFalse ( created ) #NEWLINE# self . assertEqual ( Person . objects . count ( ) , 2 ) #NEWLINE# self . assertRaises ( IntegrityError , Person . objects . get_or_create , first_name = 'Tom' , last_name = 'Smith' ) #NEWLINE# m = ManualPrimaryKeyTest . objects . create ( id = 1 , data = 'Original' ) #NEWLINE# self . assertRaises ( IntegrityError , ManualPrimaryKeyTest . objects . get_or_create , id = 1 , data = 'Different' ) #NEWLINE# self . assertEqual ( ManualPrimaryKeyTest . objects . get ( id = 1 ) . data , 'Original' )