<s> from unittest import TestCase <EOL> from mock import Mock , patch <EOL> import elasticsearch <EOL> import curator <EOL> from . import testvars as testvars <EOL> class TestActionForceMerge ( TestCase ) : <EOL> def test_init_raise_bad_client ( self ) : <EOL> self . assertRaises ( <EOL> TypeError , curator . ForceMerge , '<STR_LIT>' , max_num_segments = <NUM_LIT:2> ) <EOL> def test_init_raise_no_segment_count ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> ilo = curator . IndexList ( client ) <EOL> self . assertRaises ( <EOL> curator . MissingArgument , curator . ForceMerge , ilo ) <EOL> def test_init ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> ) <EOL> self . assertEqual ( ilo , fmo . index_list ) <EOL> self . assertEqual ( client , fmo . client ) <EOL> def test_do_dry_run ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> client . indices . forcemerge . return_value = None <EOL> client . indices . optimize . return_value = None <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> ) <EOL> self . assertIsNone ( fmo . do_dry_run ( ) ) <EOL> def test_do_action_pre5 ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> client . info . return_value = { '<STR_LIT:version>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> client . indices . optimize . return_value = None <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> ) <EOL> self . assertIsNone ( fmo . do_action ( ) ) <EOL> def test_do_action ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> client . info . return_value = { '<STR_LIT:version>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> client . indices . forcemerge . return_value = None <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> ) <EOL> self . assertIsNone ( fmo . do_action ( ) ) <EOL> def test_do_action_with_delay ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> client . info . return_value = { '<STR_LIT:version>' : { '<STR_LIT>' : '<STR_LIT>' } } <EOL> client . indices . forcemerge . return_value = None <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> , delay = <NUM_LIT> ) <EOL> self . assertIsNone ( fmo . do_action ( ) ) <EOL> def test_do_action_raises_exception ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_one <EOL> client . cluster . state . return_value = testvars . clu_state_one <EOL> client . indices . stats . return_value = testvars . stats_one <EOL> client . indices . segments . return_value = testvars . shards <EOL> client . indices . forcemerge . return_value = None <EOL> client . indices . optimize . return_value = None <EOL> client . indices . forcemerge . side_effect = testvars . fake_fail <EOL> client . indices . optimize . side_effect = testvars . fake_fail <EOL> ilo = curator . IndexList ( client ) <EOL> fmo = curator . ForceMerge ( ilo , max_num_segments = <NUM_LIT:2> ) <EOL> self . assertRaises ( curator . FailedExecution , fmo . do_action ) </s>
