Add 'index' and 'create' unit tests for workflows

Partially implements blueprint mistral-dashboard-ut

Change-Id: I3ff0cd8958edf1f50d4da10c51aae8bac652b2b5
This commit is contained in:
Zhenguo Niu 2015-08-10 17:40:56 +08:00
parent 054f579494
commit d6bddedad0
3 changed files with 81 additions and 9 deletions

View File

@ -12,9 +12,6 @@
# 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
@ -29,12 +26,7 @@ class MistralTestsMixin(object):
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

View File

@ -128,7 +128,9 @@ OPENSTACK_CINDER_FEATURES = {
}
OPENSTACK_NEUTRON_NETWORK = {
'enable_lb': True
'enable_lb': False,
'enable_firewall': False,
'enable_vpn': False
}
OPENSTACK_HYPERVISOR_FEATURES = {

View File

@ -0,0 +1,78 @@
# 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 contextlib
from django.core.urlresolvers import reverse
import mock
from mistraldashboard.test import helpers as test
INDEX_URL = reverse('horizon:mistral:workflows:index')
CREATE_URL = reverse('horizon:mistral:workflows:create')
class WorkflowsTest(test.TestCase):
def test_index(self):
with contextlib.nested(
mock.patch('mistraldashboard.api.workflow_list',
return_value=self.mistralclient_workflows.list()),):
res = self.client.get(INDEX_URL)
self.assertTemplateUsed(res, 'mistral/workflows/index.html')
def test_create_get(self):
res = self.client.get(CREATE_URL)
self.assertTemplateUsed(res, 'mistral/workflows/create.html')
def test_create_post(self):
workflow = self.mistralclient_workflows.first()
url = reverse('horizon:mistral:workflows:select_definition')
res = self.client.get(url)
self.assertTemplateUsed(
res,
'mistral/workflows/select_definition.html'
)
form_data = {
'definition_source': 'raw',
'definition_data': workflow.definition
}
with contextlib.nested(
mock.patch('mistraldashboard.api.workflow_validate',
return_value={'valid': True}),) as (mocked_validate,):
res = self.client.post(url, form_data)
self.assertTemplateUsed(res, 'mistral/workflows/create.html')
mocked_validate.assert_called_once_with(
mock.ANY,
workflow.definition
)
form_data = {
'definition': workflow.definition
}
with contextlib.nested(
mock.patch('mistraldashboard.api.workflow_create',
return_value=workflow),) as (mocked_create,):
res = self.client.post(CREATE_URL, form_data)
self.assertNoFormErrors(res)
self.assertEqual(res.status_code, 302)
self.assertRedirectsNoFollow(res, INDEX_URL)
mocked_create.assert_called_once_with(
mock.ANY,
workflow.definition
)