import python_runner from st2common.runners.python_action_wrapper import PythonActionWrapper from st2common.runners.base_action import Action from st2actions.container import service from st2common.runners.utils import get_action_class_instance from st2common.services import config as config_service from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED, LIVEACTION_STATUS_FAILED from st2common.constants.action import LIVEACTION_STATUS_TIMED_OUT from st2common.constants.pack import SYSTEM_PACK_NAME from st2tests.base import RunnerTestCase from st2tests.base import CleanDbTestCase import st2tests.base as tests_base PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/pascal_row.py') TEST_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/test.py') PATHS_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/python_paths.py') # Note: runner inherits parent args which doesn't work with tests since test pass additional # unrecognized args mock_sys = mock.Mock() mock_sys.argv = [] @mock.patch('python_runner.sys', mock_sys) class PythonRunnerTestCase(RunnerTestCase, CleanDbTestCase): register_packs = True
# limitations under the License. import os from unittest2 import TestCase import mock from st2actions.runners import pythonrunner from st2actions.container import service from st2common.constants.action import ACTIONEXEC_STATUS_SUCCEEDED, ACTIONEXEC_STATUS_FAILED from st2common.constants.pack import SYSTEM_PACK_NAME import st2tests.base as tests_base import st2tests.config as tests_config PACAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/pascal_row.py') class PythonRunnerTestCase(TestCase): @classmethod def setUpClass(cls): tests_config.parse_args() def test_runner_creation(self): runner = pythonrunner.get_runner() self.assertTrue(runner is not None, 'Creation failed. No instance.') self.assertEqual(type(runner), pythonrunner.PythonRunner, 'Creation failed. No instance.') def test_simple_action(self):
import mock import jsonschema from python_runner import python_runner from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED from st2common.constants.pack import SYSTEM_PACK_NAME from st2common.util import output_schema from st2tests.base import RunnerTestCase from st2tests.base import CleanDbTestCase from st2tests.fixturesloader import assert_submodules_are_checked_out import st2tests.base as tests_base BASE_DIR = os.path.dirname(os.path.abspath(__file__)) PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), "packs", "pythonactions/actions/pascal_row.py") MOCK_SYS = mock.Mock() MOCK_SYS.argv = [] MOCK_SYS.executable = sys.executable MOCK_EXECUTION = mock.Mock() MOCK_EXECUTION.id = "598dbf0c0640fd54bffc688b" FAIL_SCHEMA = { "notvalid": { "type": "string", }, }
from st2common.services import config as config_service from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED, LIVEACTION_STATUS_FAILED from st2common.constants.action import LIVEACTION_STATUS_TIMED_OUT from st2common.constants.action import MAX_PARAM_LENGTH from st2common.constants.pack import SYSTEM_PACK_NAME from st2common.persistence.execution import ActionExecutionOutput from python_runner.python_action_wrapper import PythonActionWrapper from st2tests.base import RunnerTestCase from st2tests.base import CleanDbTestCase from st2tests.base import blocking_eventlet_spawn from st2tests.base import make_mock_stream_readline import st2tests.base as tests_base PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/pascal_row.py') ECHOER_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/echoer.py') TEST_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/test.py') PATHS_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/python_paths.py') ACTION_1_PATH = os.path.join(tests_base.get_fixtures_path(), 'packs/dummy_pack_9/actions/list_repos_doesnt_exist.py') ACTION_2_PATH = os.path.join(tests_base.get_fixtures_path(), 'packs/dummy_pack_9/actions/invalid_syntax.py') NON_SIMPLE_TYPE_ACTION = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/non_simple_type.py') PRINT_CONFIG_ITEM_ACTION = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/print_config_item_doesnt_exist.py')
LIVEACTION_STATUS_SUCCEEDED, LIVEACTION_STATUS_FAILED, ) from st2common.constants.action import LIVEACTION_STATUS_TIMED_OUT from st2common.constants.action import MAX_PARAM_LENGTH from st2common.constants.pack import SYSTEM_PACK_NAME from st2common.persistence.execution import ActionExecutionOutput from python_runner.python_action_wrapper import PythonActionWrapper from st2tests.base import RunnerTestCase from st2tests.base import CleanDbTestCase from st2tests.base import blocking_eventlet_spawn from st2tests.base import make_mock_stream_readline from st2tests.fixturesloader import assert_submodules_are_checked_out import st2tests.base as tests_base PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), "packs", "pythonactions/actions/pascal_row.py") ECHOER_ACTION_PATH = os.path.join(tests_base.get_resources_path(), "packs", "pythonactions/actions/echoer.py") TEST_ACTION_PATH = os.path.join(tests_base.get_resources_path(), "packs", "pythonactions/actions/test.py") PATHS_ACTION_PATH = os.path.join(tests_base.get_resources_path(), "packs", "pythonactions/actions/python_paths.py") ACTION_1_PATH = os.path.join( tests_base.get_fixtures_path(), "packs/dummy_pack_9/actions/list_repos_doesnt_exist.py", ) ACTION_2_PATH = os.path.join(tests_base.get_fixtures_path(), "packs/dummy_pack_9/actions/invalid_syntax.py") NON_SIMPLE_TYPE_ACTION = os.path.join( tests_base.get_resources_path(), "packs",
from st2common.constants.action import ACTION_OUTPUT_RESULT_DELIMITER from st2common.constants.action import LIVEACTION_STATUS_SUCCEEDED, LIVEACTION_STATUS_FAILED from st2common.constants.action import LIVEACTION_STATUS_TIMED_OUT from st2common.constants.action import MAX_PARAM_LENGTH from st2common.constants.pack import SYSTEM_PACK_NAME from st2common.persistence.execution import ActionExecutionOutput from python_runner.python_action_wrapper import PythonActionWrapper from st2tests.base import RunnerTestCase from st2tests.base import CleanDbTestCase from st2tests.base import blocking_eventlet_spawn from st2tests.base import make_mock_stream_readline from st2tests.fixturesloader import assert_submodules_are_checked_out import st2tests.base as tests_base PASCAL_ROW_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/pascal_row.py') ECHOER_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/echoer.py') TEST_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/test.py') PATHS_ACTION_PATH = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/python_paths.py') ACTION_1_PATH = os.path.join(tests_base.get_fixtures_path(), 'packs/dummy_pack_9/actions/list_repos_doesnt_exist.py') ACTION_2_PATH = os.path.join(tests_base.get_fixtures_path(), 'packs/dummy_pack_9/actions/invalid_syntax.py') NON_SIMPLE_TYPE_ACTION = os.path.join(tests_base.get_resources_path(), 'packs', 'pythonactions/actions/non_simple_type.py') PRINT_VERSION_ACTION = os.path.join(tests_base.get_fixtures_path(), 'packs', 'test_content_version/actions/print_version.py')