Fix color type string processing
This commit is contained in:
@@ -61,7 +61,7 @@ class ColorType(types.TypeDecorator, ScalarCoercible):
|
||||
self.impl = types.Unicode(max_length)
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if value:
|
||||
if value and isinstance(value, colour.Color):
|
||||
return six.text_type(getattr(value, self.STORE_FORMAT))
|
||||
return value
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
from flexmock import flexmock
|
||||
from pytest import mark
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy_utils import ColorType
|
||||
@@ -18,6 +19,22 @@ class TestColorType(TestCase):
|
||||
|
||||
self.Document = Document
|
||||
|
||||
def test_string_parameter_processing(self):
|
||||
from colour import Color
|
||||
|
||||
flexmock(ColorType).should_receive('_coerce').and_return(
|
||||
u'white'
|
||||
)
|
||||
document = self.Document(
|
||||
bg_color='white'
|
||||
)
|
||||
|
||||
self.session.add(document)
|
||||
self.session.commit()
|
||||
|
||||
document = self.session.query(self.Document).first()
|
||||
assert document.bg_color.hex == Color(u'white').hex
|
||||
|
||||
def test_color_parameter_processing(self):
|
||||
from colour import Color
|
||||
|
||||
|
Reference in New Issue
Block a user