diff --git a/glanceclient/tests/unit/v2/test_metadefs_namespaces.py b/glanceclient/tests/unit/v2/test_metadefs_namespaces.py index ecc05ee5..5995e6e7 100644 --- a/glanceclient/tests/unit/v2/test_metadefs_namespaces.py +++ b/glanceclient/tests/unit/v2/test_metadefs_namespaces.py @@ -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 = [ diff --git a/glanceclient/tests/unit/v2/test_metadefs_objects.py b/glanceclient/tests/unit/v2/test_metadefs_objects.py index c565b3c7..610aaee5 100644 --- a/glanceclient/tests/unit/v2/test_metadefs_objects.py +++ b/glanceclient/tests/unit/v2/test_metadefs_objects.py @@ -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 = [ diff --git a/glanceclient/tests/unit/v2/test_metadefs_properties.py b/glanceclient/tests/unit/v2/test_metadefs_properties.py index 388bf938..11165b96 100644 --- a/glanceclient/tests/unit/v2/test_metadefs_properties.py +++ b/glanceclient/tests/unit/v2/test_metadefs_properties.py @@ -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 = [ diff --git a/glanceclient/v2/metadefs.py b/glanceclient/v2/metadefs.py index b6ba492f..84d83df7 100644 --- a/glanceclient/v2/metadefs.py +++ b/glanceclient/v2/metadefs.py @@ -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)