#NEWLINE# def test_enum_field_save( self ) : #NEWLINE# #INDENT# lamp = Lamp . objects . create ( ) #NEWLINE# self . assertEqual ( lamp . state , LampState . OFF ) #NEWLINE# lamp . state = LampState . ON #NEWLINE# lamp . save ( ) #NEWLINE# self . assertEqual ( lamp . state , LampState . ON ) #NEWLINE# self . assertEqual ( lamp . state , 1 ) #NEWLINE# self . assertRaises ( InvalidStatusOperationError , setattr , lamp , 'state' , 99 ) #NEWLINE# person = Person . objects . create ( ) #NEWLINE# pk = person . pk #NEWLINE# self . assertEqual ( person . status , PersonStatus . ALIVE ) #NEWLINE# person . status = PersonStatus . DEAD #NEWLINE# person . save ( ) #NEWLINE# self . assertTrue ( isinstance ( person . status , int ) ) #NEWLINE# self . assertEqual ( person . status , PersonStatus . DEAD ) #NEWLINE# person = Person . objects . get ( pk = pk ) #NEWLINE# self . assertEqual ( person . status , PersonStatus . DEAD ) #NEWLINE# self . assertTrue ( isinstance ( person . status , int ) ) #NEWLINE# self . assertRaises ( InvalidStatusOperationError , setattr , person , 'status' , 99 ) #NEWLINE# person = Person . objects . create ( status = PersonStatus . ALIVE ) #NEWLINE# self . assertRaises ( InvalidStatusOperationError , setattr , person , 'status' , PersonStatus . UNBORN ) #NEWLINE# person . status = PersonStatus . DEAD #NEWLINE# self . assertEqual ( person . save ( ) , 'Person.save' ) #NEWLINE# with self . assertRaises ( InvalidStatusOperationError ) : #NEWLINE# #INDENT# person . status = PersonStatus . VOID #NEWLINE# person . save ( ) #NEWLINE# #UNINDENT# self . assertTrue ( Person . objects . filter ( status = PersonStatus . DEAD ) . exists ( ) ) #NEWLINE# beer = Beer . objects . create ( ) #NEWLINE# beer . style = BeerStyle . LAGER #NEWLINE# self . assertEqual ( beer . state , BeerState . FIZZY ) #NEWLINE# beer . save ( )