Fix color type string processing

This commit is contained in:
Konsta Vesterinen
2014-01-20 17:52:41 +02:00
parent d7bbd0d7c0
commit 6fab2703a1
2 changed files with 18 additions and 1 deletions

View File

@@ -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

View File

@@ -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