def test_get(self):
        self.requests_mock.get(self.TEST_URL + URL_TEMPLATE_NAME % 'action',
                               json=ACTION)

        action = self.actions.get('action')

        self.assertIsNotNone(action)
        self.assertEqual(
            actions.Action(self.actions, ACTION).to_dict(), action.to_dict())
Exemplo n.º 2
0
    def test_get(self):
        mock = self.mock_http_get(content=ACTION)

        action = self.actions.get('action')

        self.assertIsNotNone(action)
        self.assertEqual(
            actions.Action(self.actions, ACTION).to_dict(), action.to_dict())

        mock.assert_called_once_with(URL_TEMPLATE_NAME % 'action')
    def test_list(self):
        self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
                               json={'actions': [ACTION]})

        action_list = self.actions.list()

        self.assertEqual(1, len(action_list))

        action = action_list[0]

        self.assertEqual(
            actions.Action(self.actions, ACTION).to_dict(), action.to_dict())
    def test_create_long_input(self, mock_open):
        action_long_input_dict = ACTION_DICT.copy()
        long_input = ', '.join(['var%s' % i for i in six.moves.xrange(10)])
        action_long_input_dict['input'] = long_input
        workflow_long_input = actions.Action(mock.Mock(),
                                             action_long_input_dict)
        self.client.actions.create.return_value = (workflow_long_input, )

        result = self.call(action_cmd.Create, app_args=['1.txt'])

        self.assertEqual([('a', True, cmd_base.cut(long_input),
                           'My cool action', 'test', '1', '1')], result[1])
Exemplo n.º 5
0
    def test_list(self):
        mock = self.mock_http_get(content={'actions': [ACTION]})

        action_list = self.actions.list()

        self.assertEqual(1, len(action_list))

        action = action_list[0]

        self.assertEqual(
            actions.Action(self.actions, ACTION).to_dict(), action.to_dict())

        mock.assert_called_once_with(URL_TEMPLATE)
Exemplo n.º 6
0
def data(TEST):
    # MistralActions
    TEST.mistralclient_actions = test_data_utils.TestDataContainer()
    action_1 = actions.Action(
        actions.ActionManager(None),
        {'name': 'a',
         'is_system': True,
         'input': 'param1',
         'description': 'my cool action',
         'tags': ['test'],
         'created_at': '1',
         'updated_at': '1'
         }
    )
    TEST.mistralclient_actions.add(action_1)

    # MistralExecutions
    TEST.mistralclient_executions = test_data_utils.TestDataContainer()
    execution_1 = executions.Execution(
        executions.ExecutionManager(None),
        {'id': '123',
         'workflow_name': 'my_wf',
         'description': '',
         'state': 'RUNNING',
         'input': {
             'person': {
                 'first_name': 'John',
                 'last_name': 'Doe'
             }
         }}
    )
    TEST.mistralclient_executions.add(execution_1)

    # Tasks
    TEST.mistralclient_tasks = test_data_utils.TestDataContainer()
    task_1 = tasks.Task(
        tasks.TaskManager(None),
        {'id': '1',
         'workflow_execution_id': '123',
         'name': 'my_task',
         'workflow_name': 'my_wf',
         'state': 'RUNNING',
         'type': 'ACTION',
         'tags': ['deployment', 'demo'],
         'result': {'some': 'result'}})
    TEST.mistralclient_tasks.add(task_1)

    # Workbooks
    TEST.mistralclient_workbooks = test_data_utils.TestDataContainer()
    workbook_1 = workbooks.Workbook(
        workbooks.WorkbookManager(None),
        {'name': 'a',
         'tags': ['a', 'b'],
         'created_at': '1',
         'updated_at': '1',
         'definition': WB_DEF}
    )
    TEST.mistralclient_workbooks.add(workbook_1)

    # Workflows
    TEST.mistralclient_workflows = test_data_utils.TestDataContainer()
    workflow_1 = workflows.Workflow(
        workflows.WorkflowManager(None),
        {'name': 'a',
         'tags': ['a', 'b'],
         'input': 'param',
         'created_at': '1',
         'updated_at': '1',
         'definition': WF_DEF}
    )
    TEST.mistralclient_workflows.add(workflow_1)

    # MistralActionsExecutions
    TEST.mistralclient_action_executions = test_data_utils.TestDataContainer()
    action_executions_1 = action_executions.ActionExecution(
        action_executions.ActionExecutionManager(None),
        {'id': '1',
         'name': 'a',
         'tags': ['a', 'b'],
         'workflow_name': 'my work flow',
         'task_execution_id': '1',
         'task_name': 'b',
         'description': '',
         'created_at': '1',
         'updated_at': '1',
         'accepted': True,
         'state': 'RUNNING'
         }
    )
    TEST.mistralclient_action_executions.add(action_executions_1)

    # MistralCronTriggers
    TEST.mistralclient_cron_triggers = test_data_utils.TestDataContainer()
    cron_triggers_1 = cron_triggers.CronTrigger(
        cron_triggers.CronTriggerManager(None),
        {'id': '1',
         'name': 'a',
         'workflow_name': 'my work flow',
         'pattern': '',
         'next_execution_time': '',
         'remaining_executions': '',
         'first_execution_time': '',
         'created_at': '1',
         'updated_at': '1'
         })
    TEST.mistralclient_cron_triggers.add(cron_triggers_1)
Exemplo n.º 7
0
    'namespace': 'test_namespace'
}

ACTION_DEF = """
---
version: '2.0'

base: std.echo
base-parameters:
    output: "<% $.str1 %><% $.str2 %>"
output: "<% $ %><% $ %>"
"""

ACTION_WITH_DEF_DICT = ACTION_DICT.copy()
ACTION_WITH_DEF_DICT.update({'definition': ACTION_DEF})
ACTION = actions.Action(mock, ACTION_DICT)
ACTION_WITH_DEF = actions.Action(mock, ACTION_WITH_DEF_DICT)


class TestCLIActionsV2(base.BaseCommandTest):
    @mock.patch('argparse.open', create=True)
    def test_create(self, mock_open):
        self.client.actions.create.return_value = [ACTION]

        result = self.call(action_cmd.Create, app_args=['1.txt'])

        self.assertEqual([('1234-4567-7894-7895', 'a', True, "param1",
                           'My cool action', 'test', '1', '1')], result[1])

    @mock.patch('argparse.open', create=True)
    def test_create_public(self, mock_open):