<s> from datetime import date <EOL> from django . db import IntegrityError <EOL> from django . test import TestCase <EOL> from models import Person , ManualPrimaryKeyTest <EOL> class GetOrCreateTests ( TestCase ) : <EOL> def test_get_or_create ( self ) : <EOL> p = Person . objects . create ( <EOL> first_name = '<STR_LIT>' , last_name = '<STR_LIT>' , birthday = date ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:9> ) <EOL> ) <EOL> p , created = Person . objects . get_or_create ( <EOL> first_name = "<STR_LIT>" , last_name = "<STR_LIT>" , defaults = { <EOL> "<STR_LIT>" : date ( <NUM_LIT> , <NUM_LIT:10> , <NUM_LIT:9> ) <EOL> } <EOL> ) <EOL> self . assertFalse ( created ) <EOL> self . assertEqual ( Person . objects . count ( ) , <NUM_LIT:1> ) <EOL> p , created = Person . objects . get_or_create ( <EOL> first_name = '<STR_LIT>' , last_name = '<STR_LIT>' , defaults = { <EOL> '<STR_LIT>' : date ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) <EOL> } <EOL> ) <EOL> self . assertTrue ( created ) <EOL> self . assertEqual ( Person . objects . count ( ) , <NUM_LIT:2> ) <EOL> p , created = Person . objects . get_or_create ( <EOL> first_name = '<STR_LIT>' , last_name = '<STR_LIT>' , defaults = { <EOL> '<STR_LIT>' : date ( <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> ) <EOL> } <EOL> ) <EOL> self . assertFalse ( created ) <EOL> self . assertEqual ( Person . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertRaises ( IntegrityError , <EOL> Person . objects . get_or_create , first_name = "<STR_LIT>" , last_name = "<STR_LIT>" <EOL> ) <EOL> m = ManualPrimaryKeyTest . objects . create ( id = <NUM_LIT:1> , data = "<STR_LIT>" ) <EOL> self . assertRaises ( IntegrityError , <EOL> ManualPrimaryKeyTest . objects . get_or_create , id = <NUM_LIT:1> , data = "<STR_LIT>" <EOL> ) <EOL> self . assertEqual ( ManualPrimaryKeyTest . objects . get ( id = <NUM_LIT:1> ) . data , "<STR_LIT>" ) </s>
