From 1676c1d2a09adfb7a7fe91c689a359e16190a698 Mon Sep 17 00:00:00 2001 From: Zhenguo Niu Date: Fri, 24 Jul 2015 22:19:09 +0800 Subject: [PATCH] Add test helpers and test data Change-Id: I1f752d5ae35794a4db640e777c4952485c55d63d --- mistraldashboard/test/helpers.py | 43 +++++++ mistraldashboard/test/test_data/__init__.py | 0 .../test/test_data/mistral_data.py | 109 ++++++++++++++++++ mistraldashboard/test/test_data/utils.py | 32 +++++ test-requirements.txt | 1 + 5 files changed, 185 insertions(+) create mode 100644 mistraldashboard/test/helpers.py create mode 100644 mistraldashboard/test/test_data/__init__.py create mode 100644 mistraldashboard/test/test_data/mistral_data.py create mode 100644 mistraldashboard/test/test_data/utils.py diff --git a/mistraldashboard/test/helpers.py b/mistraldashboard/test/helpers.py new file mode 100644 index 0000000..62f1bd7 --- /dev/null +++ b/mistraldashboard/test/helpers.py @@ -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 diff --git a/mistraldashboard/test/test_data/__init__.py b/mistraldashboard/test/test_data/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/mistraldashboard/test/test_data/mistral_data.py b/mistraldashboard/test/test_data/mistral_data.py new file mode 100644 index 0000000..b32ad62 --- /dev/null +++ b/mistraldashboard/test/test_data/mistral_data.py @@ -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) diff --git a/mistraldashboard/test/test_data/utils.py b/mistraldashboard/test/test_data/utils.py new file mode 100644 index 0000000..05ec044 --- /dev/null +++ b/mistraldashboard/test/test_data/utils.py @@ -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) diff --git a/test-requirements.txt b/test-requirements.txt index 4534b5c..09f70c2 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -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