Skip to content

Commit f5bfa90

Browse files
ffigielValian
authored andcommitted
py27 compatibility for ValidationResult
1 parent a374e4a commit f5bfa90

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

business_logic/core.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import functools
22

3+
import six
4+
35
from business_logic.exceptions import LogicException
46

57

@@ -57,6 +59,7 @@ def wrapper(*args, **kwargs):
5759
return wrapper
5860

5961

62+
@six.python_2_unicode_compatible
6063
class ValidationResult(object):
6164
"""
6265
Class for storing result of validation function.
@@ -94,4 +97,4 @@ def __repr__(self):
9497
return u'<PermissionResult success={} error={}>'.format(self.success, self.error)
9598

9699
def __str__(self):
97-
return str(self.error) if self.error else u''
100+
return six.text_type(self.error) if self.error else u''

tests/test_api.py

+5
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ def test_comparision(self):
5353
# comparision with other types should raise false
5454
self.assertFalse(success_result == 1)
5555

56+
def test_unicode_is_handled_properly(self):
57+
unicode_text = u'Zażółć gęślą jaźń'
58+
result = core.ValidationResult(success=False, error=exceptions.LogicException(unicode_text))
59+
self.assertEqual(u'{}'.format(result), unicode_text)
60+
5661

5762
class TestValidator(TestCase):
5863

0 commit comments

Comments
 (0)