Expanded flavor template test coverage

Added tests have to do with exception handling;
thus, this patch also formally brings tuskar
exceptions into the tuskar_ui codebase

Change-Id: I198c66ecfe3eb539c803f50f6a1a21fa16ff707a
Implements: blueprint flavors-dashboard-tests
This commit is contained in:
Tzu-Mainn Chen 2013-08-15 21:48:17 -04:00
parent a1f62577bf
commit 9b190ac678
6 changed files with 113 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import os
from django.utils.translation import ugettext_lazy as _
from openstack_dashboard import exceptions
from tuskar_ui import exceptions
DEBUG = True
TEMPLATE_DEBUG = DEBUG

26
tuskar_ui/exceptions.py Normal file
View File

@ -0,0 +1,26 @@
# vim: tabstop=4 shiftwidth=4 softtabstop=4
# Copyright 2012 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
# All Rights Reserved.
#
# Copyright 2012 Nebula, Inc.
#
# 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 import exceptions
import tuskarclient.exc as tuskarclient
NOT_FOUND = exceptions.NOT_FOUND
RECOVERABLE = exceptions.RECOVERABLE + (tuskarclient.ClientException,)
UNAUTHORIZED = exceptions.UNAUTHORIZED

View File

@ -40,6 +40,35 @@ class FlavorTemplatesTests(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(
resp, reverse('horizon:infrastructure:resource_management:index'))
@test.create_stubs({tuskar.FlavorTemplate: ('list', 'create')})
def test_create_flavor_template_post_exception(self):
template = self.tuskar_flavor_templates.first()
tuskar.FlavorTemplate.list(
IsA(http.HttpRequest)).AndReturn([])
tuskar.FlavorTemplate.create(
IsA(http.HttpRequest),
name=template.name,
cpu=0,
memory=0,
storage=0,
ephemeral_disk=0,
swap_disk=0).AndRaise(self.exceptions.tuskar)
self.mox.ReplayAll()
url = reverse('horizon:infrastructure:resource_management:'
'flavor_templates:create')
data = {'name': template.name,
'cpu': 0,
'memory': 0,
'storage': 0,
'ephemeral_disk': 0,
'swap_disk': 0}
resp = self.client.post(url, data)
self.assertMessageCount(resp, error=1)
@test.create_stubs({tuskar.FlavorTemplate: ('list', 'update', 'get')})
def test_edit_flavor_template_get(self):
template = self.tuskar_flavor_templates.first() # has no extra spec
@ -90,6 +119,37 @@ class FlavorTemplatesTests(test.BaseAdminViewTests):
self.assertRedirectsNoFollow(
resp, reverse('horizon:infrastructure:resource_management:index'))
@test.create_stubs({tuskar.FlavorTemplate: ('list', 'update')})
def test_edit_flavor_template_post_exception(self):
template = self.tuskar_flavor_templates.first() # has no extra spec
tuskar.FlavorTemplate.list(IsA(http.HttpRequest)).AndReturn(
self.tuskar_flavor_templates.list())
tuskar.FlavorTemplate.update(
IsA(http.HttpRequest),
template_id=template.id,
name=template.name,
cpu=0,
memory=0,
storage=0,
ephemeral_disk=0,
swap_disk=0).AndRaise(self.exceptions.tuskar)
self.mox.ReplayAll()
data = {'flavor_template_id': template.id,
'name': template.name,
'cpu': 0,
'memory': 0,
'storage': 0,
'ephemeral_disk': 0,
'swap_disk': 0}
url = reverse(
'horizon:infrastructure:resource_management:flavor_templates:edit',
args=[template.id])
resp = self.client.post(url, data)
self.assertMessageCount(resp, error=1)
@test.create_stubs({tuskar.FlavorTemplate: ('list', 'delete')})
def test_delete_flavor_template(self):
template = self.tuskar_flavor_templates.first()
@ -123,3 +183,21 @@ class FlavorTemplatesTests(test.BaseAdminViewTests):
res = self.client.get(url)
self.assertTemplateUsed(res, "infrastructure/resource_management/"
"flavor_templates/detail.html")
@test.create_stubs({tuskar.FlavorTemplate: ('get',)})
def test_detail_flavor_template_exception(self):
template = self.tuskar_flavor_templates.first()
tuskar.FlavorTemplate.get(
IsA(http.HttpRequest),
template.id).AndRaise(self.exceptions.tuskar)
tuskar.FlavorTemplate.resource_classes = self.tuskar_resource_classes
self.mox.ReplayAll()
url = reverse('horizon:infrastructure:resource_management:'
'flavor_templates:detail', args=[template.id])
res = self.client.get(url)
self.assertRedirectsNoFollow(
res, reverse('horizon:infrastructure:resource_management:index'))

View File

@ -5,9 +5,9 @@ from django.utils.translation import ugettext_lazy as _
from horizon.test.settings import * # noqa
from horizon.utils.secret_key import generate_or_read_from_file
from openstack_dashboard.exceptions import NOT_FOUND
from openstack_dashboard.exceptions import RECOVERABLE
from openstack_dashboard.exceptions import UNAUTHORIZED
from tuskar_ui.exceptions import NOT_FOUND
from tuskar_ui.exceptions import RECOVERABLE
from tuskar_ui.exceptions import UNAUTHORIZED
TEST_DIR = os.path.dirname(os.path.abspath(__file__))

View File

@ -18,6 +18,7 @@ from keystoneclient import exceptions as keystone_exceptions
from neutronclient.common import exceptions as neutron_exceptions
from novaclient import exceptions as nova_exceptions
from swiftclient import client as swift_exceptions
import tuskarclient.exc as tuskar_exceptions
from openstack_dashboard.test.test_data.utils import TestDataContainer
@ -68,3 +69,6 @@ def data(TEST):
cinder_exception = cinder_exceptions.BadRequest
TEST.exceptions.cinder = create_stubbed_exception(cinder_exception)
tuskar_exception = tuskar_exceptions.ClientException
TEST.exceptions.tuskar = create_stubbed_exception(tuskar_exception)

View File

@ -15,13 +15,13 @@
def load_test_data(load_onto=None):
from openstack_dashboard.test.test_data import cinder_data
from openstack_dashboard.test.test_data import exceptions
from openstack_dashboard.test.test_data import glance_data
from openstack_dashboard.test.test_data import heat_data
from openstack_dashboard.test.test_data import keystone_data
from openstack_dashboard.test.test_data import neutron_data
from openstack_dashboard.test.test_data import nova_data
from openstack_dashboard.test.test_data import swift_data
from tuskar_ui.test.test_data import exceptions
from tuskar_ui.test.test_data import tuskar_data
# The order of these loaders matters, some depend on others.