Fix phonenumber string coercion
This commit is contained in:
@@ -4,6 +4,12 @@ Changelog
|
||||
Here you can see the full list of changes between each SQLAlchemy-Utils release.
|
||||
|
||||
|
||||
0.27.12 (2014-12-xx)
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
- Fixed PhoneNumber string coercion (#93)
|
||||
|
||||
|
||||
0.27.11 (2014-12-06)
|
||||
^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import six
|
||||
from sqlalchemy import types
|
||||
from sqlalchemy_utils.exceptions import ImproperlyConfigured
|
||||
from sqlalchemy_utils.utils import str_coercible
|
||||
from .scalar_coercible import ScalarCoercible
|
||||
|
||||
|
||||
@@ -13,6 +14,7 @@ except ImportError:
|
||||
BasePhoneNumber = object
|
||||
|
||||
|
||||
@str_coercible
|
||||
class PhoneNumber(BasePhoneNumber):
|
||||
'''
|
||||
Extends a PhoneNumber class from `Python phonenumbers library`_. Adds
|
||||
@@ -66,9 +68,6 @@ class PhoneNumber(BasePhoneNumber):
|
||||
def __unicode__(self):
|
||||
return self.national
|
||||
|
||||
def __str__(self):
|
||||
return six.text_type(self.national).encode('utf-8')
|
||||
|
||||
|
||||
class PhoneNumberType(types.TypeDecorator, ScalarCoercible):
|
||||
"""
|
||||
|
@@ -1,6 +1,8 @@
|
||||
from pytest import mark
|
||||
from tests import TestCase
|
||||
import six
|
||||
import sqlalchemy as sa
|
||||
from pytest import mark
|
||||
|
||||
from tests import TestCase
|
||||
from sqlalchemy_utils import PhoneNumberType, PhoneNumber
|
||||
from sqlalchemy_utils.types import phone_number
|
||||
|
||||
@@ -45,8 +47,11 @@ class TestPhoneNumber(object):
|
||||
|
||||
def test_phone_number_str_repr(self):
|
||||
number = PhoneNumber('+358401234567')
|
||||
assert number.__unicode__() == number.national
|
||||
assert number.__str__() == number.national.encode('utf-8')
|
||||
if six.PY2:
|
||||
assert unicode(number) == number.national
|
||||
assert str(number) == number.national.encode('utf-8')
|
||||
else:
|
||||
assert str(number) == number.national
|
||||
|
||||
|
||||
@mark.skipif('phone_number.phonenumbers is None')
|
||||
|
Reference in New Issue
Block a user