Allow mutable argument to be passed to BinaryObject artifacts

According to spec description [1] binary data should always be
immutable. Before this commit, passing 'mutable' argument lead
to exception, because it was passed to a function twice. This commit
makes BinaryObject's silently ignore mutable=False and raises an
appropriate exception in case mutable=True is passed.

Change-Id: Ib42871004c792b840f8af0316c3b8177c4ecf706
Closes-Bug: #1542430
This commit is contained in:
Kirill Zaitsev 2016-02-08 15:28:18 +03:00
parent 132906146d
commit 8415297e5b
2 changed files with 18 additions and 1 deletions

View File

@ -516,8 +516,12 @@ class BinaryObject(declarative.BlobDefinition, Blob):
:param max_locations: maximum number of locations in the associated
Blob
"""
mutable = kwargs.pop('mutable', False)
if mutable:
raise exc.InvalidArtifactTypePropertyDefinition(
_("BinaryObject property cannot be declared mutable"))
super(BinaryObject, self).__init__(default=None, readonly=False,
mutable=False, **kwargs)
mutable=mutable, **kwargs)
self._max_file_size = max_file_size
self._min_file_size = min_file_size
self._min_locations = min_locations

View File

@ -13,6 +13,7 @@
# under the License.
import datetime
import functools
import mock
import six
@ -225,6 +226,18 @@ class TestDeclarativeProperties(test_utils.BaseTestCase):
self.assertRaises(exc.InvalidArtifactPropertyValue, setattr, tt,
'with_pattern', '.123.')
def test_binary_object_mutable(self):
def declare_blob(mutable):
class BLOB(BASE):
prop = defs.BinaryObject(mutable=mutable)
return BLOB
blob = declare_blob(False)()
self.assertFalse(blob.metadata.attributes.all['prop'].mutable)
self.assertRaises(exc.InvalidArtifactTypePropertyDefinition,
functools.partial(declare_blob, True))
def test_default_and_allowed_violates_string_constrains(self):
def declare_wrong_default():
class WrongType(BASE):