<s> import yaml <EOL> from mock import Mock , MagicMock <EOL> from st2tests . base import BaseActionTestCase <EOL> from ncm_config_download import NcmConfigDownload <EOL> __all__ = [ <EOL> '<STR_LIT>' <EOL> ] <EOL> MOCK_CONFIG_BLANK = "<STR_LIT>" <EOL> MOCK_CONFIG_FULL = """<STR_LIT>""" <EOL> class NcmConfigDownloadTestCase ( BaseActionTestCase ) : <EOL> action_cls = NcmConfigDownload <EOL> def test_run_no_config ( self ) : <EOL> config = yaml . safe_load ( MOCK_CONFIG_BLANK ) <EOL> self . assertRaises ( ValueError , NcmConfigDownload , config ) <EOL> def test_run_basic_config ( self ) : <EOL> config = yaml . safe_load ( MOCK_CONFIG_FULL ) <EOL> action = self . get_action_instance ( config ) <EOL> self . assertIsInstance ( action , NcmConfigDownload ) <EOL> def test_run_connect_fail ( self ) : <EOL> config = yaml . safe_load ( MOCK_CONFIG_FULL ) <EOL> action = self . get_action_instance ( config ) <EOL> action . connect = Mock ( side_effect = ValueError ( <EOL> '<STR_LIT>' ) ) <EOL> self . assertRaises ( ValueError , <EOL> action . run , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_run_ncm_node_not_found ( self ) : <EOL> orion_data = { '<STR_LIT>' : [ ] } <EOL> config = yaml . safe_load ( MOCK_CONFIG_FULL ) <EOL> action = self . get_action_instance ( config ) <EOL> action . connect = MagicMock ( return_value = True ) <EOL> action . query = MagicMock ( return_value = orion_data ) <EOL> self . assertRaises ( IndexError , <EOL> action . run , <EOL> "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> def test_run_ncm_download_complete ( self ) : <EOL> expected = { '<STR_LIT>' : { '<STR_LIT:status>' : '<STR_LIT>' } , <EOL> '<STR_LIT>' : { '<STR_LIT:status>' : '<STR_LIT>' } <EOL> } <EOL> query_data = [ <EOL> { '<STR_LIT>' : [ { '<STR_LIT>' : "<STR_LIT>" } ] } , <EOL> { '<STR_LIT>' : [ { '<STR_LIT>' : <NUM_LIT:2> } ] } , <EOL> { '<STR_LIT>' : [ { '<STR_LIT>' : <NUM_LIT:2> } ] } <EOL> ] <EOL> invoke_data = [ "<STR_LIT>" ] <EOL> config = yaml . safe_load ( MOCK_CONFIG_FULL ) <EOL> action = self . get_action_instance ( config ) <EOL> action . connect = MagicMock ( return_value = True ) <EOL> action . query = Mock ( side_effect = query_data ) <EOL> action . invoke = MagicMock ( return_value = invoke_data ) <EOL> result = action . run ( "<STR_LIT>" , <EOL> "<STR_LIT>" , <EOL> [ "<STR_LIT>" , "<STR_LIT>" ] ) <EOL> self . assertEqual ( result , expected ) </s>
