diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index c4ee610..a8c382b 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -606,10 +606,19 @@ class TestPhotoObject(TestPhotos): "name": "Test Name"}) self.assertEqual(repr(photo), "") + 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 diff --git a/trovebox/objects/trovebox_object.py b/trovebox/objects/trovebox_object.py index b7132bc..20023fa 100644 --- a/trovebox/objects/trovebox_object.py +++ b/trovebox/objects/trovebox_object.py @@ -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): """