Fix Metadef Object update issue with python-glanceclient

Disallowed fields(schema, created_at and updated_at) were
getting deleted from Metadef namespace instead of Metadef object.

Change-Id: Id80e204c7af1ac6926c66627d290a15c4e6b00d9
Closes-Bug: #1433884
This commit is contained in:
Lakshmi N Sampath 2015-03-18 22:21:19 -07:00 committed by Kamil Rykowski
parent 9c172fb056
commit 5d933b0dd5
4 changed files with 38 additions and 2 deletions

View File

@ -664,6 +664,14 @@ class TestNamespaceController(testtools.TestCase):
self.assertRaises(TypeError, self.controller.update, NAMESPACE1,
**properties)
def test_update_namespace_disallowed_fields(self):
properties = {'display_name': 'My Updated Name'}
self.controller.update(NAMESPACE1, **properties)
actual = self.api.calls
_disallowed_fields = ['self', 'schema', 'created_at', 'updated_at']
for key in actual[1][3]:
self.assertNotIn(key, _disallowed_fields)
def test_delete_namespace(self):
self.controller.delete(NAMESPACE1)
expect = [

View File

@ -304,6 +304,24 @@ class TestObjectController(testtools.TestCase):
self.assertRaises(TypeError, self.controller.update, NAMESPACE1,
OBJECT1, **properties)
def test_update_object_disallowed_fields(self):
properties = {
'description': 'UPDATED_DESCRIPTION'
}
self.controller.update(NAMESPACE1, OBJECT1, **properties)
actual = self.api.calls
# API makes three calls(GET, PUT, GET) for object update.
# PUT has the request body in the list
'''('PUT', '/v2/metadefs/namespaces/Namespace1/objects/Object1', {},
[('description', 'UPDATED_DESCRIPTION'),
('name', 'Object1'),
('properties', ...),
('required', [])])'''
_disallowed_fields = ['self', 'schema', 'created_at', 'updated_at']
for key in actual[1][3]:
self.assertNotIn(key, _disallowed_fields)
def test_delete_object(self):
self.controller.delete(NAMESPACE1, OBJECT1)
expect = [

View File

@ -280,6 +280,16 @@ class TestPropertyController(testtools.TestCase):
self.assertRaises(TypeError, self.controller.update, NAMESPACE1,
PROPERTY1, **properties)
def test_update_property_disallowed_fields(self):
properties = {
'description': 'UPDATED_DESCRIPTION'
}
self.controller.update(NAMESPACE1, PROPERTY1, **properties)
actual = self.api.calls
_disallowed_fields = ['created_at', 'updated_at']
for key in actual[1][3]:
self.assertNotIn(key, _disallowed_fields)
def test_delete_property(self):
self.controller.delete(NAMESPACE1, PROPERTY1)
expect = [

View File

@ -348,8 +348,8 @@ class ObjectController(object):
# Remove read-only parameters.
read_only = ['schema', 'updated_at', 'created_at']
for elem in read_only:
if elem in namespace:
del namespace[elem]
if elem in obj:
del obj[elem]
url = '/v2/metadefs/namespaces/{0}/objects/{1}'.format(namespace,
object_name)