<s> import mock <EOL> from st2actions . runners import actionchainrunner as acr <EOL> from st2actions . container . service import RunnerContainerService <EOL> from st2common . exceptions import actionrunner as runnerexceptions <EOL> from st2common . constants . action import LIVEACTION_STATUS_RUNNING <EOL> from st2common . constants . action import LIVEACTION_STATUS_SUCCEEDED <EOL> from st2common . constants . action import LIVEACTION_STATUS_CANCELED <EOL> from st2common . constants . action import LIVEACTION_STATUS_TIMED_OUT <EOL> from st2common . constants . action import LIVEACTION_STATUS_FAILED <EOL> from st2common . models . api . notification import NotificationsHelper <EOL> from st2common . models . db . liveaction import LiveActionDB <EOL> from st2common . models . db . keyvalue import KeyValuePairDB <EOL> from st2common . models . system . common import ResourceReference <EOL> from st2common . persistence . keyvalue import KeyValuePair <EOL> from st2common . persistence . runner import RunnerType <EOL> from st2common . services import action as action_service <EOL> from st2common . util import action_db as action_db_util <EOL> from st2common . exceptions . action import ParameterRenderingFailedException <EOL> from st2tests import DbTestCase <EOL> from st2tests . fixturesloader import FixturesLoader <EOL> class DummyActionExecution ( object ) : <EOL> def __init__ ( self , status = LIVEACTION_STATUS_SUCCEEDED , result = '<STR_LIT>' ) : <EOL> self . id = None <EOL> self . status = status <EOL> self . result = result <EOL> FIXTURES_PACK = '<STR_LIT>' <EOL> TEST_MODELS = { <EOL> '<STR_LIT>' : [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : [ '<STR_LIT>' ] <EOL> } <EOL> MODELS = FixturesLoader ( ) . load_models ( fixtures_pack = FIXTURES_PACK , <EOL> fixtures_dict = TEST_MODELS ) <EOL> ACTION_1 = MODELS [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> ACTION_2 = MODELS [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> ACTION_3 = MODELS [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> RUNNER = MODELS [ '<STR_LIT>' ] [ '<STR_LIT>' ] <EOL> CHAIN_1_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_2_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_ACTION_CALL_NO_PARAMS_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_NO_DEFAULT = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_NO_DEFAULT_2 = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_BAD_DEFAULT = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_BROKEN_ON_SUCCESS_PATH_STATIC_TASK_NAME = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_BROKEN_ON_FAILURE_PATH_STATIC_TASK_NAME = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_FIRST_TASK_RENDER_FAIL_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_SECOND_TASK_RENDER_FAIL_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_LIST_TEMP_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_DICT_TEMP_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_DEP_INPUT = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_DEP_RESULTS_INPUT = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> MALFORMED_CHAIN_PATH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_TYPED_PARAMS = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_SYSTEM_PARAMS = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_WITH_ACTIONPARAM_VARS = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_WITH_SYSTEM_VARS = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_WITH_PUBLISH = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_WITH_PUBLISH_PARAM_RENDERING_FAILURE = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_WITH_INVALID_ACTION = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_ACTION_PARAMS_AND_PARAMETERS_ATTRIBUTE = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_ACTION_PARAMS_ATTRIBUTE = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_ACTION_PARAMETERS_ATTRIBUTE = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_ACTION_INVALID_PARAMETER_TYPE = FixturesLoader ( ) . get_fixture_file_path_abs ( <EOL> FIXTURES_PACK , '<STR_LIT>' , '<STR_LIT>' ) <EOL> CHAIN_NOTIFY_API = { '<STR_LIT>' : { '<STR_LIT>' : { '<STR_LIT:message>' : '<STR_LIT>' } } } <EOL> CHAIN_NOTIFY_DB = NotificationsHelper . to_model ( CHAIN_NOTIFY_API ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = RUNNER ) ) <EOL> class TestActionChainRunner ( DbTestCase ) : <EOL> def test_runner_creation ( self ) : <EOL> runner = acr . get_runner ( ) <EOL> self . assertTrue ( runner ) <EOL> self . assertTrue ( runner . runner_id ) <EOL> def test_malformed_chain ( self ) : <EOL> try : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = MALFORMED_CHAIN_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> self . assertTrue ( False , '<STR_LIT>' ) <EOL> except runnerexceptions . ActionRunnerPreRunError : <EOL> self . assertTrue ( True ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_success_path ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_1_PATH <EOL> chain_runner . action = ACTION_1 <EOL> action_ref = ResourceReference . to_string_reference ( name = ACTION_1 . name , <EOL> pack = ACTION_1 . pack ) <EOL> chain_runner . liveaction = LiveActionDB ( action = action_ref ) <EOL> chain_runner . liveaction . notify = CHAIN_NOTIFY_DB <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_chain_second_task_times_out ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_2_PATH <EOL> chain_runner . action = ACTION_1 <EOL> original_run_action = chain_runner . _run_action <EOL> def mock_run_action ( * args , ** kwargs ) : <EOL> original_live_action = args [ <NUM_LIT:0> ] <EOL> liveaction = original_run_action ( * args , ** kwargs ) <EOL> if original_live_action . action == '<STR_LIT>' : <EOL> liveaction . status = LIVEACTION_STATUS_TIMED_OUT <EOL> return liveaction <EOL> chain_runner . _run_action = mock_run_action <EOL> action_ref = ResourceReference . to_string_reference ( name = ACTION_1 . name , <EOL> pack = ACTION_1 . pack ) <EOL> chain_runner . liveaction = LiveActionDB ( action = action_ref ) <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , _ , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_TIMED_OUT ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_task_is_canceled_while_running ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_2_PATH <EOL> chain_runner . action = ACTION_1 <EOL> original_run_action = chain_runner . _run_action <EOL> def mock_run_action ( * args , ** kwargs ) : <EOL> original_live_action = args [ <NUM_LIT:0> ] <EOL> if original_live_action . action == '<STR_LIT>' : <EOL> status = LIVEACTION_STATUS_CANCELED <EOL> else : <EOL> status = LIVEACTION_STATUS_SUCCEEDED <EOL> request . return_value = ( DummyActionExecution ( status = status ) , None ) <EOL> liveaction = original_run_action ( * args , ** kwargs ) <EOL> return liveaction <EOL> chain_runner . _run_action = mock_run_action <EOL> action_ref = ResourceReference . to_string_reference ( name = ACTION_1 . name , <EOL> pack = ACTION_1 . pack ) <EOL> chain_runner . liveaction = LiveActionDB ( action = action_ref ) <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , _ , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_CANCELED ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:2> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_success_task_action_call_with_no_params ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_ACTION_CALL_NO_PARAMS_PATH <EOL> chain_runner . action = ACTION_1 <EOL> action_ref = ResourceReference . to_string_reference ( name = ACTION_1 . name , <EOL> pack = ACTION_1 . pack ) <EOL> chain_runner . liveaction = LiveActionDB ( action = action_ref ) <EOL> chain_runner . liveaction . notify = CHAIN_NOTIFY_DB <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_no_default ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_NO_DEFAULT <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> default_node = chain_runner . chain_holder . actionchain . default <EOL> first_node = chain_runner . chain_holder . actionchain . chain [ <NUM_LIT:0> ] <EOL> self . assertEqual ( default_node , first_node . name ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_no_default_multiple_options ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_NO_DEFAULT_2 <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> default_node = chain_runner . chain_holder . actionchain . default <EOL> first_node = chain_runner . chain_holder . actionchain . chain [ <NUM_LIT:0> ] <EOL> self . assertEqual ( default_node , first_node . name ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:2> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_bad_default ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_BAD_DEFAULT <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> expected_msg = '<STR_LIT>' <EOL> self . assertRaisesRegexp ( runnerexceptions . ActionRunnerPreRunError , <EOL> expected_msg , chain_runner . pre_run ) <EOL> @ mock . patch ( '<STR_LIT>' , mock . MagicMock ( ) ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , mock . MagicMock ( <EOL> return_value = DummyActionExecution ( ) ) ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( status = LIVEACTION_STATUS_RUNNING ) , None ) ) <EOL> def test_chain_runner_success_path_with_wait ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_1_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( status = LIVEACTION_STATUS_FAILED ) , None ) ) <EOL> def test_chain_runner_failure_path ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_1_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , _ , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_FAILED ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:2> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_broken_on_success_path_static_task_name ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_BROKEN_ON_SUCCESS_PATH_STATIC_TASK_NAME <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> expected_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertRaisesRegexp ( runnerexceptions . ActionRunnerPreRunError , <EOL> expected_msg , chain_runner . pre_run ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_broken_on_failure_path_static_task_name ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_BROKEN_ON_FAILURE_PATH_STATIC_TASK_NAME <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> expected_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertRaisesRegexp ( runnerexceptions . ActionRunnerPreRunError , <EOL> expected_msg , chain_runner . pre_run ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , side_effect = RuntimeError ( '<STR_LIT>' ) ) <EOL> def test_chain_runner_action_exception ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_1_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , results , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_FAILED ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:2> ) <EOL> error_count = <NUM_LIT:0> <EOL> for task_result in results [ '<STR_LIT>' ] : <EOL> if task_result [ '<STR_LIT:result>' ] . get ( '<STR_LIT:error>' , None ) : <EOL> error_count += <NUM_LIT:1> <EOL> self . assertEqual ( error_count , <NUM_LIT:2> ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_str_param_temp ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_FIRST_TASK_RENDER_FAIL_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , { "<STR_LIT>" : "<STR_LIT:1>" } ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_list_param_temp ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_LIST_TEMP_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , { "<STR_LIT>" : "<STR_LIT>" } ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_dict_param_temp ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_DICT_TEMP_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { "<STR_LIT>" : { "<STR_LIT>" : "<STR_LIT>" , "<STR_LIT>" : "<STR_LIT:2>" , "<STR_LIT>" : "<STR_LIT:1>" } } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( result = { '<STR_LIT>' : '<STR_LIT:1>' } ) , None ) ) <EOL> def test_chain_runner_dependent_param_temp ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_DEP_INPUT <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : <NUM_LIT:2> , '<STR_LIT>' : <NUM_LIT:3> , '<STR_LIT>' : <NUM_LIT:4> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_values = [ { u'<STR_LIT>' : u'<STR_LIT:1>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT:1>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT:1>' , u'<STR_LIT>' : u'<STR_LIT:1>' , u'<STR_LIT>' : u'<STR_LIT:1>' } ] <EOL> for call_args in request . call_args_list : <EOL> self . assertTrue ( call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . parameters in expected_values ) <EOL> expected_values . remove ( call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . parameters ) <EOL> self . assertEqual ( len ( expected_values ) , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( result = { '<STR_LIT>' : '<STR_LIT:1>' } ) , None ) ) <EOL> def test_chain_runner_dependent_results_param ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_DEP_RESULTS_INPUT <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_values = [ { u'<STR_LIT>' : u'<STR_LIT:1>' } , <EOL> { u'<STR_LIT>' : u'<STR_LIT:1>' } , <EOL> { u'<STR_LIT>' : u"<STR_LIT>" } ] <EOL> self . assertEqual ( request . call_count , <NUM_LIT:3> ) <EOL> for call_args in request . call_args_list : <EOL> self . assertTrue ( call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . parameters in expected_values ) <EOL> expected_values . remove ( call_args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] . parameters ) <EOL> self . assertEqual ( len ( expected_values ) , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( RunnerType , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = RUNNER ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_missing_param_temp ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_FIRST_TASK_RENDER_FAIL_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertEqual ( request . call_count , <NUM_LIT:0> , '<STR_LIT>' ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_failure_during_param_rendering_single_task ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_FIRST_TASK_RENDER_FAIL_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , result , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_FAILED ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , [ ] ) <EOL> self . assertTrue ( '<STR_LIT:error>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result [ '<STR_LIT:error>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' in result [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_failure_during_param_rendering_multiple_tasks ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_SECOND_TASK_RENDER_FAIL_PATH <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> status , result , _ = chain_runner . run ( { } ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_FAILED ) <EOL> self . assertEqual ( len ( result [ '<STR_LIT>' ] ) , <NUM_LIT:1> ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] [ <NUM_LIT:0> ] [ '<STR_LIT:name>' ] , '<STR_LIT>' ) <EOL> expected_error = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( '<STR_LIT:error>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result ) <EOL> self . assertTrue ( '<STR_LIT>' in result [ '<STR_LIT:error>' ] ) <EOL> self . assertTrue ( expected_error in result [ '<STR_LIT:error>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' in result [ '<STR_LIT>' ] ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_typed_params ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_TYPED_PARAMS <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : <NUM_LIT:1> , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : <NUM_LIT> } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { '<STR_LIT>' : True , <EOL> '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : <NUM_LIT> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : [ '<STR_LIT:1>' , '<STR_LIT>' ] , <EOL> '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:1>' } } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_typed_system_params ( self , request ) : <EOL> kvps = [ ] <EOL> try : <EOL> kvps . append ( KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT:a>' , value = '<STR_LIT:1>' ) ) ) <EOL> kvps . append ( KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT>' , value = '<STR_LIT>' ) ) ) <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_SYSTEM_PARAMS <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> finally : <EOL> for kvp in kvps : <EOL> KeyValuePair . delete ( kvp ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_vars_system_params ( self , request ) : <EOL> kvps = [ ] <EOL> try : <EOL> kvps . append ( KeyValuePair . add_or_update ( KeyValuePairDB ( name = '<STR_LIT:a>' , value = '<STR_LIT>' ) ) ) <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_WITH_SYSTEM_VARS <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> finally : <EOL> for kvp in kvps : <EOL> KeyValuePair . delete ( kvp ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_vars_action_params ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_WITH_ACTIONPARAM_VARS <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> chain_runner . run ( { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( result = { '<STR_LIT>' : '<STR_LIT>' } ) , None ) ) <EOL> def test_chain_runner_publish ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_WITH_PUBLISH <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . runner_parameters = { '<STR_LIT>' : True } <EOL> chain_runner . pre_run ( ) <EOL> action_parameters = { '<STR_LIT>' : '<STR_LIT>' } <EOL> _ , result , _ = chain_runner . run ( action_parameters = action_parameters ) <EOL> self . assertNotEqual ( chain_runner . chain_holder . actionchain , None ) <EOL> expected_value = { '<STR_LIT>' : <NUM_LIT:1> , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT>' : action_parameters [ '<STR_LIT>' ] } <EOL> mock_args , _ = request . call_args <EOL> self . assertEqual ( mock_args [ <NUM_LIT:0> ] . parameters , expected_value ) <EOL> self . assertEqual ( result [ '<STR_LIT>' ] , <EOL> { '<STR_LIT>' : u'<STR_LIT>' , '<STR_LIT>' : u'<STR_LIT>' } ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_runner_publish_param_rendering_failure ( self , request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_WITH_PUBLISH_PARAM_RENDERING_FAILURE <EOL> chain_runner . action = ACTION_1 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> try : <EOL> chain_runner . run ( { } ) <EOL> except ParameterRenderingFailedException as e : <EOL> expected_error = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertTrue ( expected_error in str ( e ) ) <EOL> pass <EOL> else : <EOL> self . fail ( '<STR_LIT>' ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_2 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_chain_task_passes_invalid_parameter_type_to_action ( self , mock_request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_ACTION_INVALID_PARAMETER_TYPE <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> action_parameters = { } <EOL> expected_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertRaisesRegexp ( ValueError , expected_msg , chain_runner . run , <EOL> action_parameters = action_parameters ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = None ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , <EOL> return_value = ( DummyActionExecution ( result = { '<STR_LIT>' : '<STR_LIT>' } ) , None ) ) <EOL> def test_action_chain_runner_referenced_action_doesnt_exist ( self , mock_request ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_WITH_INVALID_ACTION <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> action_parameters = { } <EOL> status , output , _ = chain_runner . run ( action_parameters = action_parameters ) <EOL> expected_error = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_FAILED ) <EOL> self . assertTrue ( expected_error in output [ '<STR_LIT:error>' ] ) <EOL> self . assertTrue ( '<STR_LIT>' in output [ '<STR_LIT>' ] , output [ '<STR_LIT>' ] ) <EOL> def test_exception_is_thrown_if_both_params_and_parameters_attributes_are_provided ( self ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_ACTION_PARAMS_AND_PARAMETERS_ATTRIBUTE <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> expected_msg = ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> self . assertRaisesRegexp ( runnerexceptions . ActionRunnerPreRunError , expected_msg , <EOL> chain_runner . pre_run ) <EOL> @ mock . patch . object ( action_db_util , '<STR_LIT>' , <EOL> mock . MagicMock ( return_value = ACTION_1 ) ) <EOL> @ mock . patch . object ( action_service , '<STR_LIT>' , return_value = ( DummyActionExecution ( ) , None ) ) <EOL> def test_params_and_parameters_attributes_both_work ( self , _ ) : <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_ACTION_PARAMS_ATTRIBUTE <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> original_build_liveaction_object = chain_runner . _build_liveaction_object <EOL> def mock_build_liveaction_object ( action_node , resolved_params , parent_context ) : <EOL> self . assertEqual ( resolved_params , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> original_build_liveaction_object ( action_node = action_node , <EOL> resolved_params = resolved_params , <EOL> parent_context = parent_context ) <EOL> chain_runner . _build_liveaction_object = mock_build_liveaction_object <EOL> action_parameters = { } <EOL> status , output , _ = chain_runner . run ( action_parameters = action_parameters ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_SUCCEEDED ) <EOL> chain_runner = acr . get_runner ( ) <EOL> chain_runner . entry_point = CHAIN_ACTION_PARAMETERS_ATTRIBUTE <EOL> chain_runner . action = ACTION_2 <EOL> chain_runner . container_service = RunnerContainerService ( ) <EOL> chain_runner . pre_run ( ) <EOL> def mock_build_liveaction_object ( action_node , resolved_params , parent_context ) : <EOL> self . assertEqual ( resolved_params , { '<STR_LIT>' : '<STR_LIT>' } ) <EOL> original_build_liveaction_object ( action_node = action_node , <EOL> resolved_params = resolved_params , <EOL> parent_context = parent_context ) <EOL> chain_runner . _build_liveaction_object = mock_build_liveaction_object <EOL> action_parameters = { } <EOL> status , output , _ = chain_runner . run ( action_parameters = action_parameters ) <EOL> self . assertEqual ( status , LIVEACTION_STATUS_SUCCEEDED ) <EOL> @ classmethod <EOL> def tearDownClass ( cls ) : <EOL> FixturesLoader ( ) . delete_models_from_db ( MODELS ) </s>
