diff --git a/mistraldashboard/test/helpers.py b/mistraldashboard/test/helpers.py index 62f1bd7..b3df112 100644 --- a/mistraldashboard/test/helpers.py +++ b/mistraldashboard/test/helpers.py @@ -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 diff --git a/mistraldashboard/test/settings.py b/mistraldashboard/test/settings.py index 2848d71..7b6dd02 100644 --- a/mistraldashboard/test/settings.py +++ b/mistraldashboard/test/settings.py @@ -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 = { diff --git a/mistraldashboard/workflows/tests.py b/mistraldashboard/workflows/tests.py new file mode 100644 index 0000000..61bb5a9 --- /dev/null +++ b/mistraldashboard/workflows/tests.py @@ -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 + )