Merge "Generate better validation error message when using name regexes"
This commit is contained in:
commit
564f8b25cb
@ -16,11 +16,11 @@ import copy
|
|||||||
|
|
||||||
from nova.api.validation import parameter_types
|
from nova.api.validation import parameter_types
|
||||||
|
|
||||||
availability_zone = copy.deepcopy(parameter_types.name)
|
availability_zone = {'oneOf': [parameter_types.name, {'type': 'null'}]}
|
||||||
availability_zone['type'] = ['string', 'null']
|
availability_zone_with_leading_trailing_spaces = {
|
||||||
availability_zone_with_leading_trailing_spaces = copy.deepcopy(parameter_types.
|
'oneOf': [parameter_types.name_with_leading_trailing_spaces,
|
||||||
name_with_leading_trailing_spaces)
|
{'type': 'null'}]
|
||||||
availability_zone_with_leading_trailing_spaces['type'] = ['string', 'null']
|
}
|
||||||
|
|
||||||
|
|
||||||
create = {
|
create = {
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
"""Tests for the aggregates admin api."""
|
"""Tests for the aggregates admin api."""
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
import uuid
|
||||||
from webob import exc
|
from webob import exc
|
||||||
|
|
||||||
from nova.api.openstack.compute import aggregates as aggregates_v21
|
from nova.api.openstack.compute import aggregates as aggregates_v21
|
||||||
@ -264,6 +265,19 @@ class AggregateTestCaseV21(test.NoDBTestCase):
|
|||||||
{"name": "test",
|
{"name": "test",
|
||||||
"availability_zone": ""}})
|
"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):
|
def test_create_with_extra_invalid_arg(self):
|
||||||
self.assertRaises(self.bad_request, self.controller.create,
|
self.assertRaises(self.bad_request, self.controller.create,
|
||||||
self.req, body={"name": "test",
|
self.req, body={"name": "test",
|
||||||
@ -381,6 +395,21 @@ class AggregateTestCaseV21(test.NoDBTestCase):
|
|||||||
self.assertRaises(self.bad_request, self.controller.update,
|
self.assertRaises(self.bad_request, self.controller.update,
|
||||||
self.req, "2", body=test_metadata)
|
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):
|
def test_update_with_bad_aggregate(self):
|
||||||
test_metadata = {"aggregate": {"name": "test_name"}}
|
test_metadata = {"aggregate": {"name": "test_name"}}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user