From 3a1cc85b205e40f891d3c4b07427ca8ddc955a8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89ric=20Lemoine?= Date: Wed, 12 Sep 2012 08:55:10 +0200 Subject: breaking up PGDialect.get_columns, and add PostGIS column reflection tests --- test/dialect/test_postgresql.py | 49 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) (limited to 'test/dialect/test_postgresql.py') diff --git a/test/dialect/test_postgresql.py b/test/dialect/test_postgresql.py index 371a8c018..44955c9b8 100644 --- a/test/dialect/test_postgresql.py +++ b/test/dialect/test_postgresql.py @@ -1713,6 +1713,55 @@ class ReflectionTest(fixtures.TestBase): eq_(ind, [{'unique': False, 'column_names': [u'y'], 'name': u'idx1'}]) conn.close() +class PostGISColumnReflection(fixtures.TestBase): + __only_on__ = 'postgresql' + + class Geometry(object): + def __init__(self, geometry_type=None, srid=None): + self.geometry_type = geometry_type + self.srid = srid + + ischema_names = None + + @classmethod + def setup_class(cls): + ischema_names = postgresql.PGDialect.ischema_names + postgresql.PGDialect.ischema_names = ischema_names.copy() + postgresql.PGDialect.ischema_names['geometry'] = cls.Geometry + cls.ischema_names = ischema_names + + @classmethod + def teardown_class(cls): + postgresql.PGDialect.ischema_names = cls.ischema_names + cls.ischema_names = None + + def test_geometry(self): + dialect = postgresql.PGDialect() + column_info = dialect._get_column_info( + 'geom', 'geometry', None, False, + {}, {}, 'public') + assert isinstance(column_info['type'], self.Geometry) + assert column_info['type'].geometry_type is None + assert column_info['type'].srid is None + + def test_geometry_with_type(self): + dialect = postgresql.PGDialect() + column_info = dialect._get_column_info( + 'geom', 'geometry(POLYGON)', None, False, + {}, {}, 'public') + assert isinstance(column_info['type'], self.Geometry) + assert column_info['type'].geometry_type == 'POLYGON' + assert column_info['type'].srid is None + + def test_geometry_with_type_and_srid(self): + dialect = postgresql.PGDialect() + column_info = dialect._get_column_info( + 'geom', 'geometry(POLYGON,4326)', None, False, + {}, {}, 'public') + assert isinstance(column_info['type'], self.Geometry) + assert column_info['type'].geometry_type == 'POLYGON' + assert column_info['type'].srid == '4326' + class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): __only_on__ = 'postgresql' -- cgit v1.2.1