Add invalid attribute names to exception
When creating a resource via CreateManager.create(), an InvalidAttribute could be raised for invalid attributes (attributes that are not needed to create the resource). The raised exception had no message. This changes the exception to include a list of all the invalid attributes as well as indicate what the problem is. Change-Id: Iaea056ea6946a6f813f8081c26f62dcfe63d1bbd
This commit is contained in:
parent
9a85728d1b
commit
1e37be4484
@ -201,11 +201,18 @@ class CreateManager(Manager):
|
||||
"""
|
||||
|
||||
new = {}
|
||||
invalid = []
|
||||
for (key, value) in kwargs.items():
|
||||
if key in self._creation_attributes:
|
||||
new[key] = value
|
||||
else:
|
||||
raise exc.InvalidAttribute()
|
||||
invalid.append(key)
|
||||
if invalid:
|
||||
raise exc.InvalidAttribute(
|
||||
'The attribute(s) "%(attrs)s" are invalid; they are not '
|
||||
'needed to create %(resource)s.' %
|
||||
{'resource': self._resource_name,
|
||||
'attrs': '","'.join(invalid)})
|
||||
url = self._path()
|
||||
resp, body = self.api.json_request('POST', url, body=new)
|
||||
if body:
|
||||
|
@ -117,8 +117,9 @@ class ManagerTestCase(testtools.TestCase):
|
||||
self.assertIsInstance(resource, TestableResource)
|
||||
|
||||
def test_create_with_invalid_attribute(self):
|
||||
self.assertRaises(exc.InvalidAttribute, self.manager.create,
|
||||
**INVALID_ATTRIBUTE_TESTABLE_RESOURCE)
|
||||
self.assertRaisesRegex(exc.InvalidAttribute, "non-existent-attribute",
|
||||
self.manager.create,
|
||||
**INVALID_ATTRIBUTE_TESTABLE_RESOURCE)
|
||||
|
||||
def test_get(self):
|
||||
resource = self.manager.get(TESTABLE_RESOURCE['uuid'])
|
||||
|
Loading…
Reference in New Issue
Block a user