Skip to content

Commit

Permalink
Add PhoneNumber python_type, refs #248
Browse files Browse the repository at this point in the history
  • Loading branch information
kvesteri committed Oct 20, 2016
1 parent b1f84e5 commit ec7e2fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 1 addition & 3 deletions sqlalchemy_utils/types/phone_number.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,7 @@ class User(self.Base):
"""
STORE_FORMAT = 'e164'
impl = types.Unicode(20)

def python_type(self, text):
return self._coerce(text)
python_type = PhoneNumber

def __init__(self, region='US', max_length=20, *args, **kwargs):
# Bail if phonenumbers is not found.
Expand Down
3 changes: 3 additions & 0 deletions tests/types/test_phonenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ def test_empty_phone_number_is_equiv_to_none(self, session, User):
session.refresh(user)
assert user.phone_number is None

def test_uses_phonenumber_class_as_python_type(self):
assert PhoneNumberType().python_type is PhoneNumber

@pytest.mark.usefixtures('user')
def test_phone_number_is_none(self, session, User):
phone_number = None
Expand Down

0 comments on commit ec7e2fe

Please sign in to comment.