Merge branch 'sneakypete81-unicode_repr' into development
This commit is contained in:
commit
ab17b26dff
2 changed files with 18 additions and 3 deletions
|
@ -606,6 +606,11 @@ class TestPhotoObject(TestPhotos):
|
||||||
"name": "Test Name"})
|
"name": "Test Name"})
|
||||||
self.assertEqual(repr(photo), "<Photo 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')
|
@mock.patch.object(trovebox.Trovebox, 'post')
|
||||||
def test_photo_object_create_attribute(self, _):
|
def test_photo_object_create_attribute(self, _):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
"""
|
"""
|
||||||
Base object supporting the storage of custom fields as attributes
|
Base object supporting the storage of custom fields as attributes
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
import sys
|
||||||
|
|
||||||
class TroveboxObject(object):
|
class TroveboxObject(object):
|
||||||
""" Base object supporting the storage of custom fields as attributes """
|
""" Base object supporting the storage of custom fields as attributes """
|
||||||
_type = "None"
|
_type = "None"
|
||||||
|
@ -41,11 +45,17 @@ class TroveboxObject(object):
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if self.name is not None:
|
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:
|
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:
|
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):
|
def get_fields(self):
|
||||||
""" Returns this object's attributes """
|
""" Returns this object's attributes """
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue