diff --git a/tests/unit/test_photos.py b/tests/unit/test_photos.py index c1ed191..05500d2 100644 --- a/tests/unit/test_photos.py +++ b/tests/unit/test_photos.py @@ -443,3 +443,31 @@ class TestPhotoTransform(TestPhotos): photo.transform(rotate="90") mock_post.assert_called_with("/photo/1a/transform.json", rotate="90") self.assertEqual(photo.get_fields(), self.test_photos_dict[1]) + +class TestPhotoObject(TestPhotos): + def test_photo_object_repr_without_id_or_name(self): + """ + Ensure the string representation on an object includes its class name + if the ID and Name attributes don't exist. + """ + photo = trovebox.objects.photo.Photo(self.client, {}) + self.assertEqual(repr(photo), "") + + def test_photo_object_repr_with_id(self): + """ Ensure the string representation on an object includes its id, if present """ + photo = trovebox.objects.photo.Photo(self.client, {"id": "Test ID"}) + self.assertEqual(repr(photo), "") + + def test_photo_object_repr_with_id_and_name(self): + """ Ensure the string representation on an object includes its name, if present """ + photo = trovebox.objects.photo.Photo(self.client, {"id": "Test ID", + "name": "Test Name"}) + self.assertEqual(repr(photo), "") + + def test_photo_object_illegal_attribute(self): + """ + Check that an exception is raised when creating an Photo object + with an illegal attribute + """ + with self.assertRaises(ValueError): + photo = trovebox.objects.photo.Photo(self.client, {"_illegal_attribute": "test"}) diff --git a/trovebox/objects/trovebox_object.py b/trovebox/objects/trovebox_object.py index 49122ec..86284dc 100644 --- a/trovebox/objects/trovebox_object.py +++ b/trovebox/objects/trovebox_object.py @@ -39,11 +39,11 @@ class TroveboxObject(object): def __repr__(self): if self.name is not None: - return "<%s name='%s'>" % (self.__class__, self.name) + return "<%s name='%s'>" % (self.__class__.__name__, self.name) elif self.id is not None: - return "<%s id='%s'>" % (self.__class__, self.id) + return "<%s id='%s'>" % (self.__class__.__name__, self.id) else: - return "<%s>" % (self.__class__) + return "<%s>" % (self.__class__.__name__) def get_fields(self): """ Returns this object's attributes """