Beispiel #1
0
    def test_update(self):
        url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
        self.requests_mock.put(url, json=ACTION_EXEC)

        body = {
            'state': ACTION_EXEC['state']
        }

        action_execution = self.action_executions.update(
            ACTION_EXEC['id'],
            ACTION_EXEC['state']
        )

        self.assertIsNotNone(action_execution)

        expected = action_executions.ActionExecution(
            self.action_executions,
            ACTION_EXEC
        ).to_dict()

        self.assertEqual(
            expected,
            action_execution.to_dict()
        )

        self.assertEqual(body, self.requests_mock.last_request.json())
    def test_update(self):
        states = ['IDLE', 'RUNNING', 'SUCCESS', 'ERROR', 'CANCELLED']

        for state in states:
            action_ex_dict = copy.deepcopy(ACTION_EX_DICT)
            action_ex_dict['state'] = state
            action_ex_dict['state_info'] = 'testing update'
            action_ex_obj = action_ex.ActionExecution(mock, action_ex_dict)
            self.client.action_executions.update.return_value = action_ex_obj

            result = self.call(action_ex_cmd.Update,
                               app_args=['id', '--state', state])

            expected_result = (action_ex_dict['id'], action_ex_dict['name'],
                               action_ex_dict['workflow_name'],
                               action_ex_dict['workflow_namespace'],
                               action_ex_dict['task_name'],
                               action_ex_dict['task_execution_id'],
                               action_ex_dict['state'],
                               action_ex_dict['state_info'],
                               action_ex_dict['accepted'],
                               action_ex_dict['created_at'],
                               action_ex_dict['updated_at'])

            self.assertEqual(expected_result, result[1])
Beispiel #3
0
    def test_get(self):
        url = self.TEST_URL + URL_TEMPLATE_ID % ACTION_EXEC['id']
        self.requests_mock.get(url, json=ACTION_EXEC)

        action_execution = self.action_executions.get(ACTION_EXEC['id'])

        expected = action_executions.ActionExecution(self.action_executions,
                                                     ACTION_EXEC).to_dict()

        self.assertEqual(expected, action_execution.to_dict())
    def test_get(self):
        mock = self.mock_http_get(content=ACTION_EXEC)

        action_execution = self.action_executions.get(ACTION_EXEC['id'])

        self.assertEqual(action_executions.ActionExecution(
            self.action_executions, ACTION_EXEC
        ).to_dict(), action_execution.to_dict())

        mock.assert_called_once_with(
            URL_TEMPLATE_ID % ACTION_EXEC['id'])
Beispiel #5
0
    def test_list(self):
        self.requests_mock.get(self.TEST_URL + URL_TEMPLATE,
                               json={'action_executions': [ACTION_EXEC]})

        action_execution_list = self.action_executions.list()

        self.assertEqual(1, len(action_execution_list))
        action_execution = action_execution_list[0]

        expected = action_executions.ActionExecution(self.action_executions,
                                                     ACTION_EXEC).to_dict()

        self.assertEqual(expected, action_execution.to_dict())
    def test_list(self):
        mock = self.mock_http_get(
            content={'action_executions': [ACTION_EXEC]}
        )

        action_execution_list = self.action_executions.list()

        self.assertEqual(1, len(action_execution_list))
        action_execution = action_execution_list[0]

        self.assertEqual(action_executions.ActionExecution(
            self.action_executions, ACTION_EXEC
        ).to_dict(), action_execution.to_dict())

        mock.assert_called_once_with(URL_TEMPLATE)
Beispiel #7
0
    def test_create(self):
        self.requests_mock.post(self.TEST_URL + URL_TEMPLATE,
                                json=ACTION_EXEC,
                                status_code=201)

        body = {'name': ACTION_EXEC['name']}

        action_execution = self.action_executions.create(
            'my_action_execution', {})

        self.assertIsNotNone(action_execution)
        self.assertEqual(
            action_executions.ActionExecution(self.action_executions,
                                              ACTION_EXEC).to_dict(),
            action_execution.to_dict())

        self.assertEqual(body, self.requests_mock.last_request.json())
    def test_update(self):
        mock = self.mock_http_put(content=ACTION_EXEC)
        body = {
            'state': ACTION_EXEC['state']
        }

        action_execution = self.action_executions.update(
            ACTION_EXEC['id'],
            ACTION_EXEC['state']
        )

        self.assertIsNotNone(action_execution)
        self.assertEqual(action_executions.ActionExecution(
            self.action_executions, ACTION_EXEC
        ).to_dict(), action_execution.to_dict())

        mock.assert_called_once_with(
            URL_TEMPLATE_ID % ACTION_EXEC['id'], json.dumps(body))
    def test_create(self):
        mock = self.mock_http_post(content=ACTION_EXEC)
        body = {
            'name': ACTION_EXEC['name']
        }

        action_execution = self.action_executions.create(
            'my_action_execution',
            {}
        )

        self.assertIsNotNone(action_execution)
        self.assertEqual(action_executions.ActionExecution(
            self.action_executions, ACTION_EXEC
        ).to_dict(), action_execution.to_dict())

        mock.assert_called_once_with(
            URL_TEMPLATE, json.dumps(body))
Beispiel #10
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)
    'state_info': 'RUNNING somehow.',
    'accepted': True,
    'created_at': '1',
    'updated_at': '1',
}

ACTION_EX_RESULT = {"test": "is", "passed": "successfully"}
ACTION_EX_INPUT = {"param1": "val1", "param2": 2}

ACTION_EX_WITH_OUTPUT_DICT = ACTION_EX_DICT.copy()
ACTION_EX_WITH_OUTPUT_DICT.update({'output': json.dumps(ACTION_EX_RESULT)})

ACTION_EX_WITH_INPUT_DICT = ACTION_EX_DICT.copy()
ACTION_EX_WITH_INPUT_DICT.update({'input': json.dumps(ACTION_EX_INPUT)})

ACTION_EX = action_ex.ActionExecution(mock, ACTION_EX_DICT)
ACTION_EX_WITH_OUTPUT = action_ex.ActionExecution(mock,
                                                  ACTION_EX_WITH_OUTPUT_DICT)
ACTION_EX_WITH_INPUT = action_ex.ActionExecution(mock,
                                                 ACTION_EX_WITH_INPUT_DICT)


class TestCLIActionExecutions(base.BaseCommandTest):
    def test_create(self):
        (self.client.action_executions.create.return_value
         ) = ACTION_EX_WITH_OUTPUT

        self.call(action_ex_cmd.Create,
                  app_args=['some', '{"output": "Hello!"}'])

        self.assertDictEqual(ACTION_EX_RESULT,