<s> from ralph . lib . transitions . models import TRANSITION_ORIGINAL_STATUS <EOL> from ralph . lib . transitions . tests import TransitionTestCase <EOL> from ralph . tests . models import Order , OrderStatus <EOL> class TransitionFormTest ( TransitionTestCase ) : <EOL> def test_raise_error_when_instance_is_empty ( self ) : <EOL> with self . assertRaises ( ValueError ) : <EOL> self . _get_form ( ) ( ) <EOL> def test_raise_error_when_instance_is_incorrect ( self ) : <EOL> class IncorrectObject ( object ) : <EOL> pass <EOL> with self . assertRaises ( TypeError ) : <EOL> self . _get_form ( IncorrectObject ( ) ) ( ) <EOL> def test_action_choices ( self ) : <EOL> transition_model , transition , actions = self . _create_transition ( <EOL> Order , '<STR_LIT:test>' <EOL> ) <EOL> form = self . _get_form ( transition_model ) ( instance = transition ) <EOL> self . assertCountEqual ( <EOL> [ x [ <NUM_LIT:1> ] for x in form . fields [ '<STR_LIT>' ] . choices ] , <EOL> [ getattr ( Order , a . name ) . verbose_name for a in actions ] <EOL> ) <EOL> def test_source_choices ( self ) : <EOL> transition_model , transition , actions = self . _create_transition ( <EOL> Order , '<STR_LIT:test>' <EOL> ) <EOL> form = self . _get_form ( transition_model ) ( instance = transition ) <EOL> self . assertCountEqual ( <EOL> [ x [ <NUM_LIT:1> ] for x in form . fields [ '<STR_LIT:source>' ] . choices ] , <EOL> [ s . name for s in OrderStatus . __choices__ ] <EOL> ) <EOL> def test_target_choices ( self ) : <EOL> transition_model , transition , actions = self . _create_transition ( <EOL> Order , '<STR_LIT:test>' <EOL> ) <EOL> form = self . _get_form ( transition_model ) ( instance = transition ) <EOL> order_status = [ s . name for s in OrderStatus . __choices__ ] <EOL> self . assertCountEqual ( <EOL> [ x [ <NUM_LIT:1> ] for x in form . fields [ '<STR_LIT:target>' ] . choices [ <NUM_LIT:1> : ] ] , <EOL> order_status + [ TRANSITION_ORIGINAL_STATUS [ <NUM_LIT:1> ] ] <EOL> ) <EOL> def test_should_raise_vaild_error_when_user_checked_two_or_more_actions_with_attachment ( self ) : <EOL> transition_model , transition , actions = self . _create_transition ( <EOL> Order , '<STR_LIT:test>' <EOL> ) <EOL> data = { <EOL> '<STR_LIT:name>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : transition_model , <EOL> '<STR_LIT:source>' : [ OrderStatus . new . id ] , <EOL> '<STR_LIT:target>' : OrderStatus . sended . id , <EOL> '<STR_LIT>' : list ( actions . values_list ( '<STR_LIT:id>' , flat = True ) ) <EOL> } <EOL> form = self . _get_form ( transition_model ) ( data , instance = transition ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors , { <EOL> '<STR_LIT>' : [ <EOL> '<STR_LIT>' <EOL> ] <EOL> } ) </s>
