Merge pull request #230 from quantus/feature/email-type-custom-length

Allow setting custom length to EmailType, refs #229
This commit is contained in:
Konsta Vesterinen 2016-07-10 12:01:00 +03:00 committed by GitHub
commit 0bcf91ceaa
3 changed files with 9 additions and 2 deletions

View File

@ -4,9 +4,12 @@ from ..operators import CaseInsensitiveComparator
class EmailType(sa.types.TypeDecorator):
impl = sa.Unicode(255)
impl = sa.Unicode
comparator_factory = CaseInsensitiveComparator
def __init__(self, length=255, *args, **kwargs):
super(EmailType, self).__init__(length=length, *args, **kwargs)
def process_bind_param(self, value, dialect):
if value is not None:
return value.lower()

View File

@ -13,7 +13,7 @@ try:
import cryptography
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives import hashes
from cryptography.hazmat.primitives.ciphers import(
from cryptography.hazmat.primitives.ciphers import (
Cipher, algorithms, modes
)
from cryptography.fernet import Fernet

View File

@ -10,6 +10,7 @@ def User(Base):
__tablename__ = 'user'
id = sa.Column(sa.Integer, primary_key=True)
email = sa.Column(EmailType)
short_email = sa.Column(EmailType(length=70))
def __repr__(self):
return 'User(%r)' % self.id
@ -30,3 +31,6 @@ class TestEmailType(object):
clause = User.email == 'Someone@example.com'
compiled = str(clause.compile(compile_kwargs={'literal_binds': True}))
assert compiled == '"user".email = lower(\'Someone@example.com\')'
def test_custom_length(self, session, User):
assert User.short_email.type.impl.length == 70