Merge branch 'sneakypete81-unicode_repr' into development

This commit is contained in:
sneakypete81 2014-02-02 20:53:47 +00:00
commit ab17b26dff
2 changed files with 18 additions and 3 deletions

View file

@ -606,6 +606,11 @@ class TestPhotoObject(TestPhotos):
"name": "Test Name"})
self.assertEqual(repr(photo), "<Photo name='Test Name'>")
def test_photo_object_repr_with_unicode_id(self):
""" Ensure that a unicode id is correctly represented """
photo = trovebox.objects.photo.Photo(self.client, {"id": "\xfcmlaut"})
self.assertIn(repr(photo), [b"<Photo id='\xc3\xbcmlaut'>", "<Photo id='\xfcmlaut'>"])
@mock.patch.object(trovebox.Trovebox, 'post')
def test_photo_object_create_attribute(self, _):
"""

View file

@ -1,6 +1,10 @@
"""
Base object supporting the storage of custom fields as attributes
"""
from __future__ import unicode_literals
import sys
class TroveboxObject(object):
""" Base object supporting the storage of custom fields as attributes """
_type = "None"
@ -41,11 +45,17 @@ class TroveboxObject(object):
def __repr__(self):
if self.name is not None:
return "<%s name='%s'>" % (self.__class__.__name__, self.name)
value = "<%s name='%s'>" % (self.__class__.__name__, self.name)
elif self.id is not None:
return "<%s id='%s'>" % (self.__class__.__name__, self.id)
value = "<%s id='%s'>" % (self.__class__.__name__, self.id)
else:
return "<%s>" % (self.__class__.__name__)
value = "<%s>" % (self.__class__.__name__)
# Python2 requires a bytestring
if sys.version < '3':
return value.encode('utf-8')
else: # pragma: no cover
return value
def get_fields(self):
""" Returns this object's attributes """