<s> from mock import MagicMock <EOL> from nose . tools import eq_ , ok_ <EOL> from pylease . cmd . rollback import Rollback , Stage <EOL> from tests import PyleaseTest <EOL> stage1 = '<STR_LIT>' <EOL> stage1_priority = <NUM_LIT:0> <EOL> stage2 = '<STR_LIT>' <EOL> stage2_priority = <NUM_LIT:2> <EOL> stage3 = '<STR_LIT>' <EOL> stage3_priority = <NUM_LIT:1> <EOL> stage1_mock = MagicMock ( ) <EOL> stage2_mock = MagicMock ( ) <EOL> stage3_mock = MagicMock ( ) <EOL> stage_execution_queue = [ ] <EOL> class RollbackTest ( PyleaseTest ) : <EOL> def setUp ( self ) : <EOL> super ( RollbackTest , self ) . setUp ( ) <EOL> global stage_execution_queue <EOL> stage_execution_queue = [ ] <EOL> class SomeRollback ( Rollback ) : <EOL> @ Stage ( stage1 , stage1_priority ) <EOL> def stage1_rollback ( self ) : <EOL> stage1_mock ( ) <EOL> stage_execution_queue . append ( stage1_mock ) <EOL> @ Stage ( stage2 , stage2_priority ) <EOL> def stage2_rollback ( self ) : <EOL> stage2_mock ( ) <EOL> stage_execution_queue . append ( stage2_mock ) <EOL> @ Stage ( stage3 , stage3_priority ) <EOL> def stage3_rollback ( self ) : <EOL> stage3_mock ( ) <EOL> stage_execution_queue . append ( stage3_mock ) <EOL> def test_rollback_mechanism_should_generate_appropriate_dictionary ( self ) : <EOL> rollback = self . SomeRollback ( ) <EOL> expected_stages = { stage1 : { rollback . stage1_rollback : ( stage1_priority , False ) } , <EOL> stage2 : { rollback . stage2_rollback : ( stage2_priority , False ) } , <EOL> stage3 : { rollback . stage3_rollback : ( stage3_priority , False ) } } <EOL> eq_ ( expected_stages , rollback . _stages ) <EOL> def test_it_must_be_possible_to_cherry_pick_enable_rollback_stages ( self ) : <EOL> rollback = self . SomeRollback ( ) <EOL> rollback . enable_stage ( stage2 ) <EOL> ok_ ( rollback . _stages [ stage2 ] [ rollback . stage2_rollback ] [ <NUM_LIT:1> ] ) <EOL> ok_ ( not rollback . _stages [ stage1 ] [ rollback . stage1_rollback ] [ <NUM_LIT:1> ] ) <EOL> def test_rollback_mechanism_should_execute_enabled_stages_in_correct_order ( self ) : <EOL> rollback = self . SomeRollback ( ) <EOL> rollback . enable_stage ( stage2 ) <EOL> rollback . enable_stage ( stage3 ) <EOL> rollback . rollback ( ) <EOL> ok_ ( stage1_mock not in stage_execution_queue ) <EOL> stage2_mock . assert_called_once_with ( ) <EOL> stage3_mock . assert_called_once_with ( ) <EOL> stage2_index = stage_execution_queue . index ( stage2_mock ) <EOL> stage3_index = stage_execution_queue . index ( stage3_mock ) <EOL> ok_ ( stage2_index < stage3_index ) </s>
