Add test helpers and test data
Change-Id: I1f752d5ae35794a4db640e777c4952485c55d63d
This commit is contained in:
parent
8881ce22bc
commit
1676c1d2a0
43
mistraldashboard/test/helpers.py
Normal file
43
mistraldashboard/test/helpers.py
Normal file
@ -0,0 +1,43 @@
|
||||
# Copyright 2015 Huawei Technologies Co., Ltd.
|
||||
#
|
||||
# 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.
|
||||
|
||||
import os
|
||||
|
||||
from django.utils import unittest
|
||||
from openstack_dashboard.test import helpers
|
||||
|
||||
from mistraldashboard.test.test_data import utils
|
||||
|
||||
|
||||
def create_stubs(stubs_to_create={}):
|
||||
return helpers.create_stubs(stubs_to_create)
|
||||
|
||||
|
||||
class MistralTestsMixin(object):
|
||||
def _setup_test_data(self):
|
||||
super(MistralTestsMixin, self)._setup_test_data()
|
||||
utils.load_test_data(self)
|
||||
|
||||
def add_panel_mocks(self):
|
||||
pass
|
||||
|
||||
|
||||
@unittest.skipIf(os.environ.get('SKIP_UNITTESTS', False),
|
||||
"The SKIP_UNITTESTS env variable is set.")
|
||||
class TestCase(MistralTestsMixin, helpers.TestCase):
|
||||
pass
|
||||
|
||||
|
||||
class APITestCase(MistralTestsMixin, helpers.APITestCase):
|
||||
pass
|
0
mistraldashboard/test/test_data/__init__.py
Normal file
0
mistraldashboard/test/test_data/__init__.py
Normal file
109
mistraldashboard/test/test_data/mistral_data.py
Normal file
109
mistraldashboard/test/test_data/mistral_data.py
Normal file
@ -0,0 +1,109 @@
|
||||
# Copyright 2015 Huawei Technologies Co., Ltd.
|
||||
#
|
||||
# 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 mistralclient.api.v2 import executions
|
||||
from mistralclient.api.v2 import tasks
|
||||
from mistralclient.api.v2 import workbooks
|
||||
from mistralclient.api.v2 import workflows
|
||||
|
||||
from openstack_dashboard.test.test_data import utils as test_data_utils
|
||||
|
||||
|
||||
# Workbooks
|
||||
WB_DEF = """
|
||||
---
|
||||
version: 2.0
|
||||
|
||||
name: wb
|
||||
|
||||
workflows:
|
||||
wf1:
|
||||
type: direct
|
||||
input:
|
||||
- param1
|
||||
- param2
|
||||
|
||||
tasks:
|
||||
task1:
|
||||
action: std.http url="localhost:8989"
|
||||
on-success:
|
||||
- test_subsequent
|
||||
|
||||
test_subsequent:
|
||||
action: std.http url="http://some_url" server_id=1
|
||||
"""
|
||||
|
||||
# Workflows
|
||||
WF_DEF = """
|
||||
version: '2.0'
|
||||
|
||||
flow:
|
||||
tasks:
|
||||
task1:
|
||||
action: nova.servers_get server="1"
|
||||
"""
|
||||
|
||||
|
||||
def data(TEST):
|
||||
# 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',
|
||||
'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)
|
32
mistraldashboard/test/test_data/utils.py
Normal file
32
mistraldashboard/test/test_data/utils.py
Normal file
@ -0,0 +1,32 @@
|
||||
# Copyright 2015 Huawei Technologies Co., Ltd.
|
||||
#
|
||||
# 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 openstack_dashboard.test.test_data import utils
|
||||
|
||||
|
||||
def load_test_data(load_onto=None):
|
||||
from mistraldashboard.test.test_data import mistral_data
|
||||
from openstack_dashboard.test.test_data import exceptions
|
||||
|
||||
# The order of these loaders matters, some depend on others.
|
||||
loaders = (
|
||||
exceptions.data,
|
||||
mistral_data.data,
|
||||
)
|
||||
if load_onto:
|
||||
for data_func in loaders:
|
||||
data_func(load_onto)
|
||||
return load_onto
|
||||
else:
|
||||
return utils.TestData(*loaders)
|
@ -10,6 +10,7 @@ coverage>=3.6
|
||||
django-nose>=1.2
|
||||
mock>=1.0
|
||||
mox>=0.5.3
|
||||
mox3>=0.7.0
|
||||
nodeenv>=0.9.4 # BSD License
|
||||
nose
|
||||
nose-exclude
|
||||
|
Loading…
x
Reference in New Issue
Block a user