models: Make sure del on attributes does not work

This commit is contained in:
Thomas Adamcik 2015-04-04 15:21:38 +02:00
parent 4faf4de7aa
commit 73415ce60f
2 changed files with 9 additions and 0 deletions

View File

@ -152,6 +152,9 @@ class ImmutableObject(object):
return super(ImmutableObject, self).__setattr__(name, value)
raise AttributeError('Object is immutable.')
def __delattr__(self, name):
raise AttributeError('Object is immutable.')
def __repr__(self):
kwarg_pairs = []
for (key, value) in sorted(self.__dict__.items()):

View File

@ -74,6 +74,12 @@ class RefTest(unittest.TestCase):
with self.assertRaises(AttributeError):
ref.name = None
# TODO: add these for the more of the models?
def test_del_name(self):
ref = Ref(name='foo')
with self.assertRaises(AttributeError):
del ref.name
def test_invalid_kwarg(self):
with self.assertRaises(TypeError):
Ref(foo='baz')