Don't raise an exception if an object's attribute starts with an underscore,
just ignore it.
This commit is contained in:
parent
be7463518b
commit
1ba21353f9
2 changed files with 15 additions and 7 deletions
|
@ -606,10 +606,19 @@ class TestPhotoObject(TestPhotos):
|
|||
"name": "Test Name"})
|
||||
self.assertEqual(repr(photo), "<Photo name='Test Name'>")
|
||||
|
||||
def test_photo_object_attribute(self):
|
||||
"""
|
||||
Check that attributes are created when creating a
|
||||
Photo object
|
||||
"""
|
||||
photo = trovebox.objects.photo.Photo(self.client, {"attribute": "test"})
|
||||
self.assertEqual(photo.attribute, "test")
|
||||
|
||||
def test_photo_object_illegal_attribute(self):
|
||||
"""
|
||||
Check that an exception is raised when creating an Photo object
|
||||
with an illegal attribute
|
||||
Check that illegal attributes are ignored when creating a
|
||||
Photo object
|
||||
"""
|
||||
with self.assertRaises(ValueError):
|
||||
photo = trovebox.objects.photo.Photo(self.client, {"_illegal_attribute": "test"})
|
||||
photo = trovebox.objects.photo.Photo(self.client, {"_illegal_attribute": "test"})
|
||||
with self.assertRaises(AttributeError):
|
||||
value = photo._illegal_attribute
|
||||
|
|
|
@ -14,9 +14,8 @@ class TroveboxObject(object):
|
|||
def _set_fields(self, json_dict):
|
||||
""" Set this object's attributes specified in json_dict """
|
||||
for key, value in json_dict.items():
|
||||
if key.startswith("_"):
|
||||
raise ValueError("Illegal attribute: %s" % key)
|
||||
setattr(self, key, value)
|
||||
if not key.startswith("_"):
|
||||
setattr(self, key, value)
|
||||
|
||||
def _replace_fields(self, json_dict):
|
||||
"""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue