<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 TestActionAlias ( TestCase ) : <EOL> def test_init_raise ( self ) : <EOL> self . assertRaises ( curator . MissingArgument , curator . Alias ) <EOL> def test_add_raises_on_missing_parameter ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , ao . add ) <EOL> def test_add_raises_on_invalid_parameter ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> self . assertRaises ( TypeError , ao . add , [ ] ) <EOL> def test_add_single ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . add ( ilo ) <EOL> self . assertEqual ( testvars . alias_one_add , ao . actions ) <EOL> def test_add_single_with_extra_settings ( 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> ilo = curator . IndexList ( client ) <EOL> esd = { <EOL> '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT:user>' : '<STR_LIT>' } } <EOL> } <EOL> ao = curator . Alias ( name = '<STR_LIT>' , extra_settings = esd ) <EOL> ao . add ( ilo ) <EOL> self . assertEqual ( testvars . alias_one_add_with_extras , ao . actions ) <EOL> def test_remove_single ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . remove ( ilo ) <EOL> self . assertEqual ( testvars . alias_one_rm , ao . actions ) <EOL> def test_add_multiple ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_two <EOL> client . cluster . state . return_value = testvars . clu_state_two <EOL> client . indices . stats . return_value = testvars . stats_two <EOL> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . add ( ilo ) <EOL> cmp = sorted ( ao . actions , key = lambda k : k [ '<STR_LIT>' ] [ '<STR_LIT:index>' ] ) <EOL> self . assertEqual ( testvars . alias_two_add , cmp ) <EOL> def test_remove_multiple ( self ) : <EOL> client = Mock ( ) <EOL> client . indices . get_settings . return_value = testvars . settings_two <EOL> client . cluster . state . return_value = testvars . clu_state_two <EOL> client . indices . stats . return_value = testvars . stats_two <EOL> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . remove ( ilo ) <EOL> cmp = sorted ( ao . actions , key = lambda k : k [ '<STR_LIT>' ] [ '<STR_LIT:index>' ] ) <EOL> self . assertEqual ( testvars . alias_two_rm , cmp ) <EOL> def test_show_body ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . remove ( ilo ) <EOL> ao . add ( ilo ) <EOL> body = ao . body ( ) <EOL> self . assertEqual ( <EOL> testvars . alias_one_body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] , body [ '<STR_LIT>' ] [ <NUM_LIT:0> ] ) <EOL> self . assertEqual ( <EOL> testvars . alias_one_body [ '<STR_LIT>' ] [ <NUM_LIT:1> ] , body [ '<STR_LIT>' ] [ <NUM_LIT:1> ] ) <EOL> def test_raise_on_empty_body ( 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> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> self . assertRaises ( curator . ActionError , ao . body ) <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 . update_aliases . return_value = testvars . alias_success <EOL> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . add ( ilo ) <EOL> self . assertIsNone ( ao . do_dry_run ( ) ) <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 . update_aliases . return_value = testvars . alias_success <EOL> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . add ( ilo ) <EOL> self . assertIsNone ( ao . 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 . update_aliases . return_value = testvars . alias_success <EOL> client . indices . update_aliases . side_effect = testvars . four_oh_one <EOL> ilo = curator . IndexList ( client ) <EOL> ao = curator . Alias ( name = '<STR_LIT>' ) <EOL> ao . add ( ilo ) <EOL> self . assertRaises ( curator . FailedExecution , ao . do_action ) </s>
