Merge "Add invalid attribute names to exception"
This commit is contained in:
commit
b25ad9ef99
|
@ -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