From a0e0f4c289b46c0c9a051c08d7f9a1929e0e30ce Mon Sep 17 00:00:00 2001 From: Ilya Pekelny Date: Thu, 24 Jul 2014 19:27:18 +0300 Subject: Public inspector method to load enum list Provide opportunity to get enums list via an inspector instance public interface. --- test/dialect/postgresql/test_reflection.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'test/dialect/postgresql/test_reflection.py') diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 1d6a41765..26de23902 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -1,5 +1,6 @@ # coding: utf-8 +from sqlalchemy.engine import reflection from sqlalchemy.testing.assertions import eq_, assert_raises, \ AssertsExecutionResults from sqlalchemy.testing import fixtures @@ -622,6 +623,26 @@ class ReflectionTest(fixtures.TestBase): for fk in fks: eq_(fk, fk_ref[fk['name']]) + @testing.provide_metadata + def test_inspect_enums_custom_schema(self): + conn = testing.db.connect() + enum_type = postgresql.ENUM('sad', 'ok', 'happy', name='mood', + metadata=self.metadata, schema='test_schema') + enum_type.create(conn) + inspector = reflection.Inspector.from_engine(conn.engine) + eq_(inspector.load_enums(conn, 'test_schema'), { + u'test_schema.mood': {'labels': [u'sad', u'ok', u'happy']}}) + + @testing.provide_metadata + def test_inspect_enums_schema(self): + conn = testing.db.connect() + enum_type = postgresql.ENUM('cat', 'dog', 'rat', name='pet', + metadata=self.metadata) + enum_type.create(conn) + inspector = reflection.Inspector.from_engine(conn.engine) + eq_(inspector.load_enums(conn), { + u'pet': {'labels': [u'cat', u'dog', u'rat']}}) + class CustomTypeReflectionTest(fixtures.TestBase): -- cgit v1.2.1 From f39767ad727fcc9493d41451d7112d4f3459e9c4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Wed, 13 Aug 2014 17:42:33 -0400 Subject: - public method name is get_enums() - return a list of dicts like other methods do - don't combine 'schema' with 'name', leave them separate - support '*' argument so that we can retrieve cross-schema if needed - remove "conn" argument - use bound parameters for 'schema' in SQL - order by schema, name, label - adapt _load_enums changes to column reflection - changelog - module docs for get_enums() - add drop of enums to --dropfirst --- test/dialect/postgresql/test_reflection.py | 69 ++++++++++++++++++++++++------ 1 file changed, 57 insertions(+), 12 deletions(-) (limited to 'test/dialect/postgresql/test_reflection.py') diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 26de23902..bab41b0f7 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -624,24 +624,69 @@ class ReflectionTest(fixtures.TestBase): eq_(fk, fk_ref[fk['name']]) @testing.provide_metadata - def test_inspect_enums_custom_schema(self): + def test_inspect_enums_schema(self): conn = testing.db.connect() - enum_type = postgresql.ENUM('sad', 'ok', 'happy', name='mood', - metadata=self.metadata, schema='test_schema') + enum_type = postgresql.ENUM( + 'sad', 'ok', 'happy', name='mood', + schema='test_schema', + metadata=self.metadata) enum_type.create(conn) inspector = reflection.Inspector.from_engine(conn.engine) - eq_(inspector.load_enums(conn, 'test_schema'), { - u'test_schema.mood': {'labels': [u'sad', u'ok', u'happy']}}) + eq_( + inspector.get_enums('test_schema'), [{ + 'visible': False, + 'name': 'mood', + 'schema': 'test_schema', + 'labels': ['sad', 'ok', 'happy'] + }]) @testing.provide_metadata - def test_inspect_enums_schema(self): - conn = testing.db.connect() - enum_type = postgresql.ENUM('cat', 'dog', 'rat', name='pet', + def test_inspect_enums(self): + enum_type = postgresql.ENUM( + 'cat', 'dog', 'rat', name='pet', metadata=self.metadata) + enum_type.create(testing.db) + inspector = reflection.Inspector.from_engine(testing.db) + eq_(inspector.get_enums(), [ + { + 'visible': True, + 'labels': ['cat', 'dog', 'rat'], + 'name': 'pet', + 'schema': 'public' + }]) + + @testing.provide_metadata + def test_inspect_enums_star(self): + enum_type = postgresql.ENUM( + 'cat', 'dog', 'rat', name='pet', metadata=self.metadata) + schema_enum_type = postgresql.ENUM( + 'sad', 'ok', 'happy', name='mood', + schema='test_schema', metadata=self.metadata) - enum_type.create(conn) - inspector = reflection.Inspector.from_engine(conn.engine) - eq_(inspector.load_enums(conn), { - u'pet': {'labels': [u'cat', u'dog', u'rat']}}) + enum_type.create(testing.db) + schema_enum_type.create(testing.db) + inspector = reflection.Inspector.from_engine(testing.db) + + eq_(inspector.get_enums(), [ + { + 'visible': True, + 'labels': ['cat', 'dog', 'rat'], + 'name': 'pet', + 'schema': 'public' + }]) + + eq_(inspector.get_enums('*'), [ + { + 'visible': True, + 'labels': ['cat', 'dog', 'rat'], + 'name': 'pet', + 'schema': 'public' + }, + { + 'visible': False, + 'name': 'mood', + 'schema': 'test_schema', + 'labels': ['sad', 'ok', 'happy'] + }]) class CustomTypeReflectionTest(fixtures.TestBase): -- cgit v1.2.1