Added tests for TSVector autoloading
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
from functools import wraps
|
from functools import wraps
|
||||||
from sqlalchemy.orm.collections import InstrumentedList as _InstrumentedList
|
from sqlalchemy.orm.collections import InstrumentedList as _InstrumentedList
|
||||||
from sqlalchemy import types
|
from sqlalchemy import types
|
||||||
|
from sqlalchemy.dialects.postgresql.base import ischema_names
|
||||||
from .color import ColorType
|
from .color import ColorType
|
||||||
from .email import EmailType
|
from .email import EmailType
|
||||||
from .ip_address import IPAddressType
|
from .ip_address import IPAddressType
|
||||||
@@ -37,6 +38,9 @@ class TSVectorType(types.UserDefinedType):
|
|||||||
return 'tsvector'
|
return 'tsvector'
|
||||||
|
|
||||||
|
|
||||||
|
ischema_names['tsvector'] = TSVectorType
|
||||||
|
|
||||||
|
|
||||||
class InstrumentedList(_InstrumentedList):
|
class InstrumentedList(_InstrumentedList):
|
||||||
"""Enhanced version of SQLAlchemy InstrumentedList. Provides some
|
"""Enhanced version of SQLAlchemy InstrumentedList. Provides some
|
||||||
additional functionality."""
|
additional functionality."""
|
||||||
|
@@ -4,6 +4,8 @@ from tests import TestCase
|
|||||||
|
|
||||||
|
|
||||||
class TestTSVector(TestCase):
|
class TestTSVector(TestCase):
|
||||||
|
dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'
|
||||||
|
|
||||||
def create_models(self):
|
def create_models(self):
|
||||||
class User(self.Base):
|
class User(self.Base):
|
||||||
__tablename__ = 'user'
|
__tablename__ = 'user'
|
||||||
@@ -18,3 +20,13 @@ class TestTSVector(TestCase):
|
|||||||
|
|
||||||
def test_generates_table(self):
|
def test_generates_table(self):
|
||||||
assert 'search_index' in self.User.__table__.c
|
assert 'search_index' in self.User.__table__.c
|
||||||
|
|
||||||
|
def test_type_autoloading(self):
|
||||||
|
reflected_metadata = sa.schema.MetaData()
|
||||||
|
table = sa.schema.Table(
|
||||||
|
'user',
|
||||||
|
reflected_metadata,
|
||||||
|
autoload=True,
|
||||||
|
autoload_with=self.engine
|
||||||
|
)
|
||||||
|
assert isinstance(table.c['search_index'].type, TSVectorType)
|
||||||
|
Reference in New Issue
Block a user