Merge "Add invalid attribute names to exception"

This commit is contained in:
Jenkins 2016-07-01 09:07:16 +00:00 committed by Gerrit Code Review
commit b25ad9ef99
2 changed files with 11 additions and 3 deletions

View File

@ -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:

View File

@ -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'])