Merge "Generate better validation error message when using name regexes"

This commit is contained in:
Jenkins 2016-03-10 12:29:38 +00:00 committed by Gerrit Code Review
commit 564f8b25cb
2 changed files with 34 additions and 5 deletions

View File

@ -16,11 +16,11 @@ import copy
from nova.api.validation import parameter_types
availability_zone = copy.deepcopy(parameter_types.name)
availability_zone['type'] = ['string', 'null']
availability_zone_with_leading_trailing_spaces = copy.deepcopy(parameter_types.
name_with_leading_trailing_spaces)
availability_zone_with_leading_trailing_spaces['type'] = ['string', 'null']
availability_zone = {'oneOf': [parameter_types.name, {'type': 'null'}]}
availability_zone_with_leading_trailing_spaces = {
'oneOf': [parameter_types.name_with_leading_trailing_spaces,
{'type': 'null'}]
}
create = {

View File

@ -16,6 +16,7 @@
"""Tests for the aggregates admin api."""
import mock
import uuid
from webob import exc
from nova.api.openstack.compute import aggregates as aggregates_v21
@ -264,6 +265,19 @@ class AggregateTestCaseV21(test.NoDBTestCase):
{"name": "test",
"availability_zone": ""}})
@mock.patch('nova.compute.api.AggregateAPI.create_aggregate')
def test_create_with_none_availability_zone(self, mock_create_agg):
mock_create_agg.return_value = objects.Aggregate(self.context,
name='test',
uuid=uuid.uuid4(),
hosts=[],
metadata={})
body = {"aggregate": {"name": "test",
"availability_zone": None}}
result = self.controller.create(self.req, body=body)
mock_create_agg.assert_called_once_with(self.context, 'test', None)
self.assertEqual(result['aggregate']['name'], 'test')
def test_create_with_extra_invalid_arg(self):
self.assertRaises(self.bad_request, self.controller.create,
self.req, body={"name": "test",
@ -381,6 +395,21 @@ class AggregateTestCaseV21(test.NoDBTestCase):
self.assertRaises(self.bad_request, self.controller.update,
self.req, "2", body=test_metadata)
@mock.patch('nova.compute.api.AggregateAPI.update_aggregate')
def test_update_with_none_availability_zone(self, mock_update_agg):
agg_id = uuid.uuid4()
mock_update_agg.return_value = objects.Aggregate(self.context,
name='test',
uuid=agg_id,
hosts=[],
metadata={})
body = {"aggregate": {"name": "test",
"availability_zone": None}}
result = self.controller.update(self.req, agg_id, body=body)
mock_update_agg.assert_called_once_with(self.context, agg_id,
body['aggregate'])
self.assertEqual(result['aggregate']['name'], 'test')
def test_update_with_bad_aggregate(self):
test_metadata = {"aggregate": {"name": "test_name"}}