File: test_tasks.py

package info (click to toggle)
mistral-tempest-plugin 2.6.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 416 kB
  • sloc: python: 2,503; makefile: 21
file content (110 lines) | stat: -rw-r--r-- 3,780 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright 2016 NEC Corporation. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

from oslo_concurrency.fixture import lockutils
from tempest.lib import decorators

from mistral_tempest_tests.tests import base


class TasksTestsV2(base.TestCase):

    _service = 'workflowv2'

    def setUp(self):
        super(TasksTestsV2, self).setUp()
        self.useFixture(lockutils.LockFixture('mistral-workflow'))
        _, body = self.client.create_workflow('wf_v2.yaml')
        self.direct_wf_name = body['workflows'][0]['name']
        _, execution = self.client.create_execution(self.direct_wf_name)
        self.execution_id = execution['id']

    def tearDown(self):
        for wf in self.client.workflows:
            self.client.delete_obj('workflows', wf)
        self.client.workflows = []

        for wf in self.client.executions:
            self.client.delete_obj('executions', wf, force=True)
        self.client.executions = []

        super(TasksTestsV2, self).tearDown()

    @decorators.attr(type='smoke')
    @decorators.idempotent_id('81159dce-3802-44ee-a8d4-5ddca106fd91')
    def test_get_tasks_list(self):
        resp, body = self.client.get_list_obj('tasks')

        self.assertEqual(200, resp.status)
        self.assertNotEmpty(body['tasks'])

    @decorators.attr(type='sanity')
    @decorators.idempotent_id('f62664de-bd2b-4153-8d0f-5a76d78abbad')
    def test_get_task(self):
        resp, body = self.client.get_list_obj('tasks')

        self.assertEqual(200, resp.status)
        task_id = body['tasks'][-1]['id']
        resp, body = self.client.get_object('tasks', task_id)
        self.assertEqual(200, resp.status)
        self.assertEqual(self.direct_wf_name, body['workflow_name'])

    @decorators.attr(type='sanity')
    @decorators.idempotent_id('3230d694-40fd-4094-ad12-024f40a21b94')
    def test_get_tasks_of_execution(self):
        resp, body = self.client.get_list_obj(
            'tasks?workflow_execution_id=%s' % self.execution_id)

        self.assertEqual(200, resp.status)
        self.assertEqual(
            self.direct_wf_name, body['tasks'][-1]['workflow_name']
        )


class TaskTypesTestsV2(base.TestCase):

    _service = 'workflowv2'

    def setUp(self):
        super(TaskTypesTestsV2, self).setUp()

        self.useFixture(lockutils.LockFixture('mistral-workflow'))

        _, wb_body = self.client.create_workbook('wb_with_nested_wf.yaml')
        self.nested_wf_name = 'wb_with_nested_wf.wrapping_wf'
        _, execution = self.client.create_execution(self.nested_wf_name)
        self.client.wait_execution_success(execution)

    @decorators.attr(type='sanity')
    @decorators.idempotent_id('1ac726eb-b945-4b82-8755-a2fb2dc009bc')
    def test_task_type(self):
        resp, body = self.client.get_list_obj('tasks')

        self.assertEqual(200, resp.status)

        bt = body['tasks']
        ll = [[v for k, v in d.items() if 'type' in k] for d in bt]
        types_list = [item for sublist in ll for item in sublist]

        self.assertIn(
            'WORKFLOW', types_list
        )
        self.assertIn(
            'ACTION', types_list
        )

        # there are 2 tasks in the workflow one of each type
        self.assertEqual(
            2, len(types_list)
        )