Added tests for TSVector autoloading

This commit is contained in:
Konsta Vesterinen
2013-07-10 08:36:27 +03:00
parent c9699ea3b7
commit 416342afca
2 changed files with 16 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
from functools import wraps
from sqlalchemy.orm.collections import InstrumentedList as _InstrumentedList
from sqlalchemy import types
from sqlalchemy.dialects.postgresql.base import ischema_names
from .color import ColorType
from .email import EmailType
from .ip_address import IPAddressType
@@ -37,6 +38,9 @@ class TSVectorType(types.UserDefinedType):
return 'tsvector'
ischema_names['tsvector'] = TSVectorType
class InstrumentedList(_InstrumentedList):
"""Enhanced version of SQLAlchemy InstrumentedList. Provides some
additional functionality."""

View File

@@ -4,6 +4,8 @@ from tests import TestCase
class TestTSVector(TestCase):
dns = 'postgres://postgres@localhost/sqlalchemy_utils_test'
def create_models(self):
class User(self.Base):
__tablename__ = 'user'
@@ -18,3 +20,13 @@ class TestTSVector(TestCase):
def test_generates_table(self):
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)