This commit is contained in:
Konsta Vesterinen
2014-01-20 17:49:32 +02:00
parent 78bed57ba7
commit d7bbd0d7c0
2 changed files with 16 additions and 1 deletions

View File

@@ -103,7 +103,7 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible):
return Choice(value, self.choices_dict[value])
def process_bind_param(self, value, dialect):
if value:
if value and isinstance(value, Choice):
return value.code
return value

View File

@@ -1,3 +1,4 @@
from flexmock import flexmock
from pytest import raises
import sqlalchemy as sa
from sqlalchemy_utils import ChoiceType, Choice, ImproperlyConfigured
@@ -36,6 +37,20 @@ class TestChoiceType(TestCase):
type_ = self.User.__table__.c.type.type
assert type_.python_type
def test_string_processing(self):
flexmock(ChoiceType).should_receive('_coerce').and_return(
u'admin'
)
user = self.User(
type=u'admin'
)
self.session.add(user)
self.session.commit()
user = self.session.query(self.User).first()
assert user.type.value == u'Admin'
def test_parameter_processing(self):
user = self.User(
type=u'admin'