Merge "Change 422 error to 400 error"

This commit is contained in:
Jenkins 2012-09-09 09:52:22 +00:00 committed by Gerrit Code Review
commit 5f65586e9d
4 changed files with 26 additions and 26 deletions

View File

@ -93,7 +93,7 @@ def _filters(request, attr_info):
try:
result_values.append(convert_to(value))
except exceptions.InvalidInput as e:
raise webob.exc.HTTPUnprocessableEntity(str(e))
raise webob.exc.HTTPBadRequest(str(e))
else:
result_values.append(value)
if result_values:
@ -464,11 +464,11 @@ class Controller(object):
if is_required and attr not in res_dict:
msg = _("Failed to parse request. Required "
" attribute '%s' not specified") % attr
raise webob.exc.HTTPUnprocessableEntity(msg)
raise webob.exc.HTTPBadRequest(msg)
if not attr_vals['allow_post'] and attr in res_dict:
msg = _("Attribute '%s' not allowed in POST" % attr)
raise webob.exc.HTTPUnprocessableEntity(msg)
raise webob.exc.HTTPBadRequest(msg)
if attr_vals['allow_post']:
res_dict[attr] = res_dict.get(attr,
@ -477,7 +477,7 @@ class Controller(object):
for attr, attr_vals in attr_info.iteritems():
if attr in res_dict and not attr_vals['allow_put']:
msg = _("Cannot update read-only attribute %s") % attr
raise webob.exc.HTTPUnprocessableEntity(msg)
raise webob.exc.HTTPBadRequest(msg)
for attr, attr_vals in attr_info.iteritems():
# Convert values if necessary
@ -498,7 +498,7 @@ class Controller(object):
msg_dict = dict(attr=attr, reason=res)
msg = _("Invalid input for %(attr)s. "
"Reason: %(reason)s.") % msg_dict
raise webob.exc.HTTPUnprocessableEntity(msg)
raise webob.exc.HTTPBadRequest(msg)
return body
def _validate_network_tenant_ownership(self, request, resource_item):

View File

@ -435,14 +435,14 @@ class JSONV2TestCase(APIv2TestBase):
data = {'port': {'what': 'who', 'tenant_id': _uuid()}}
res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_readonly_attr(self):
data = {'network': {'name': 'net1', 'tenant_id': _uuid(),
'status': "ACTIVE"}}
res = self.api.post_json(_get_path('networks'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_bulk(self):
data = {'networks': [{'name': 'net1',
@ -473,7 +473,7 @@ class JSONV2TestCase(APIv2TestBase):
data = {'ports': [{'what': 'who', 'tenant_id': _uuid()}]}
res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_bulk_partial_body(self):
data = {'ports': [{'device_id': 'device_1',
@ -481,7 +481,7 @@ class JSONV2TestCase(APIv2TestBase):
{'tenant_id': _uuid()}]}
res = self.api.post_json(_get_path('ports'), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_attr_not_specified(self):
net_id = _uuid()
@ -644,7 +644,7 @@ class JSONV2TestCase(APIv2TestBase):
data = {'network': {'status': "NANANA"}}
res = self.api.put_json(_get_path('networks', id=_uuid()), data,
expect_errors=True)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
class V2Views(unittest.TestCase):

View File

@ -1254,7 +1254,7 @@ class TestPortsV2(QuantumDbPluginV2TestCase):
'fixed_ips': []}}
port_req = self.new_create_request('ports', data)
res = port_req.get_response(self.api)
self.assertEquals(res.status_int, 422)
self.assertEquals(res.status_int, 400)
def test_default_allocation_expiration(self):
cfg.CONF.set_override('dhcp_lease_duration', 120)
@ -1641,7 +1641,7 @@ class TestNetworksV2(QuantumDbPluginV2TestCase):
req = self.new_list_request('networks',
params='admin_state_up=fake')
res = req.get_response(self.api)
self.assertEquals(422, res.status_int)
self.assertEquals(400, res.status_int)
def test_show_network(self):
with self.network(name='net1') as net:
@ -2025,12 +2025,12 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
allocation_pools=allocation_pools)
self.assertEquals(ctx_manager.exception.code, 400)
def test_create_subnet_shared_returns_422(self):
def test_create_subnet_shared_returns_400(self):
cidr = '10.0.0.0/24'
with self.assertRaises(webob.exc.HTTPClientError) as ctx_manager:
self._test_create_subnet(cidr=cidr,
shared=True)
self.assertEquals(ctx_manager.exception.code, 422)
self.assertEquals(ctx_manager.exception.code, 400)
def test_create_subnet_inconsistent_ipv6_cidrv4(self):
with self.network() as network:
@ -2120,14 +2120,14 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
self.assertEqual(res['subnet']['gateway_ip'],
data['subnet']['gateway_ip'])
def test_update_subnet_shared_returns_422(self):
def test_update_subnet_shared_returns_400(self):
with self.network(shared=True) as network:
with self.subnet(network=network) as subnet:
data = {'subnet': {'shared': True}}
req = self.new_update_request('subnets', data,
subnet['subnet']['id'])
res = req.get_response(self.api)
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_update_subnet_inconsistent_ipv4_gatewayv6(self):
with self.network() as network:
@ -2263,7 +2263,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
subnet_req = self.new_create_request('subnets', data)
res = subnet_req.get_response(self.api)
self.assertEquals(res.status_int, 422)
self.assertEquals(res.status_int, 400)
def test_invalid_subnet(self):
with self.network() as network:
@ -2275,7 +2275,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
subnet_req = self.new_create_request('subnets', data)
res = subnet_req.get_response(self.api)
self.assertEquals(res.status_int, 422)
self.assertEquals(res.status_int, 400)
def test_invalid_ip_address(self):
with self.network() as network:
@ -2287,7 +2287,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
subnet_req = self.new_create_request('subnets', data)
res = subnet_req.get_response(self.api)
self.assertEquals(res.status_int, 422)
self.assertEquals(res.status_int, 400)
def test_invalid_uuid(self):
with self.network() as network:
@ -2299,7 +2299,7 @@ class TestSubnetsV2(QuantumDbPluginV2TestCase):
subnet_req = self.new_create_request('subnets', data)
res = subnet_req.get_response(self.api)
self.assertEquals(res.status_int, 422)
self.assertEquals(res.status_int, 400)
def test_create_subnet_with_one_dns(self):
gateway_ip = '10.0.0.1'

View File

@ -785,23 +785,23 @@ class L3NatDBTestCase(test_db_plugin.QuantumDbPluginV2TestCase):
private_sub['subnet']['id'],
None)
def test_create_floatingip_invalid_floating_network_id_returns_422(self):
def test_create_floatingip_invalid_floating_network_id_returns_400(self):
# API-level test - no need to create all objects for l3 plugin
res = self._create_floatingip('json', 'iamnotanuuid',
utils.str_uuid(), '192.168.0.1')
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_floatingip_invalid_floating_port_id_returns_422(self):
def test_create_floatingip_invalid_floating_port_id_returns_400(self):
# API-level test - no need to create all objects for l3 plugin
res = self._create_floatingip('json', utils.str_uuid(),
'iamnotanuuid', '192.168.0.1')
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_create_floatingip_invalid_fixed_ip_address_returns_422(self):
def test_create_floatingip_invalid_fixed_ip_address_returns_400(self):
# API-level test - no need to create all objects for l3 plugin
res = self._create_floatingip('json', utils.str_uuid(),
utils.str_uuid(), 'iamnotnanip')
self.assertEqual(res.status_int, 422)
self.assertEqual(res.status_int, 400)
def test_list_nets_external(self):
with self.network() as n1: