Fix #54
This commit is contained in:
@@ -103,7 +103,7 @@ class ChoiceType(types.TypeDecorator, ScalarCoercible):
|
|||||||
return Choice(value, self.choices_dict[value])
|
return Choice(value, self.choices_dict[value])
|
||||||
|
|
||||||
def process_bind_param(self, value, dialect):
|
def process_bind_param(self, value, dialect):
|
||||||
if value:
|
if value and isinstance(value, Choice):
|
||||||
return value.code
|
return value.code
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from flexmock import flexmock
|
||||||
from pytest import raises
|
from pytest import raises
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy_utils import ChoiceType, Choice, ImproperlyConfigured
|
from sqlalchemy_utils import ChoiceType, Choice, ImproperlyConfigured
|
||||||
@@ -36,6 +37,20 @@ class TestChoiceType(TestCase):
|
|||||||
type_ = self.User.__table__.c.type.type
|
type_ = self.User.__table__.c.type.type
|
||||||
assert type_.python_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):
|
def test_parameter_processing(self):
|
||||||
user = self.User(
|
user = self.User(
|
||||||
type=u'admin'
|
type=u'admin'
|
||||||
|
|||||||
Reference in New Issue
Block a user