add test for host aggregate create fail due to duplicated name

1. extend "_test_generic_create_aggregate" method to accept
   existing_aggregates array argument as mock data
2. add "test_create_aggregate_fails_duplicated_name" to test if the
   error message is shown when name conflict happens

Change-Id: I638a79defa6bc97a72feac26a314ae584d88bd10
Closes-Bug: #1617213
This commit is contained in:
shlo 2016-08-26 07:50:02 +08:00
parent 9274624843
commit d8b6fa9e44

View File

@ -14,6 +14,7 @@ import mock
from django.core.urlresolvers import reverse
from django import http
from django.utils import html
from mox3.mox import IsA # noqa
from openstack_dashboard import api
@ -78,10 +79,12 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
@test.create_stubs({api.nova: ('host_list', 'aggregate_details_list',
'aggregate_create'), })
def _test_generic_create_aggregate(self, workflow_data, aggregate,
existing_aggregates=(),
error_count=0,
expected_error_message=None):
api.nova.host_list(IsA(http.HttpRequest)).AndReturn(self.hosts.list())
api.nova.aggregate_details_list(IsA(http.HttpRequest)).AndReturn([])
api.nova.aggregate_details_list(IsA(http.HttpRequest)) \
.AndReturn(existing_aggregates)
if not expected_error_message:
api.nova.aggregate_create(
IsA(http.HttpRequest),
@ -111,9 +114,21 @@ class CreateAggregateWorkflowTests(BaseAggregateWorkflowTests):
workflow_data = self._get_create_workflow_data(aggregate)
workflow_data['name'] = ''
workflow_data['availability_zone'] = ''
self._test_generic_create_aggregate(workflow_data, aggregate, 1,
self._test_generic_create_aggregate(workflow_data, aggregate, (), 1,
u'This field is required')
def test_create_aggregate_fails_duplicated_name(self):
aggregate = self.aggregates.first()
existing_aggregates = self.aggregates.list()
workflow_data = self._get_create_workflow_data(aggregate)
expected_error_message = html \
.escape(u'The name "%s" is already used by another host aggregate.'
% aggregate.name)
self._test_generic_create_aggregate(workflow_data, aggregate,
existing_aggregates, 1,
expected_error_message)
@test.create_stubs({api.nova: ('host_list',
'aggregate_details_list',
'aggregate_create',