diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-25 17:19:03 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-10-25 17:19:03 -0400 |
commit | 46ac022e57c5279d508379f92978afd592aea5ea (patch) | |
tree | b1cfa4ecf36ba94dcba404c9adc77b68ae506cf3 | |
parent | 51e8e5df469b755ad8ba940a43281e8423789167 (diff) | |
download | sqlalchemy-46ac022e57c5279d508379f92978afd592aea5ea.tar.gz |
- move this test to PG test_reflection
- don't use locals()
-rw-r--r-- | test/dialect/postgresql/test_dialect.py | 79 | ||||
-rw-r--r-- | test/dialect/postgresql/test_reflection.py | 65 | ||||
-rw-r--r-- | test/engine/test_reflection.py | 4 |
3 files changed, 67 insertions, 81 deletions
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index 5b845cbd1..a8fedabfc 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -233,82 +233,3 @@ class MiscTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): "c %s NOT NULL" % expected ) -class InspectionTest(fixtures.TestBase, AssertsExecutionResults, AssertsCompiledSQL): - - __only_on__ = 'postgresql' - - def test_get_foreign_keys(self): - """ - PGDialect.get_foreign_keys() - """ - metadata = MetaData(testing.db) - person = Table('person', metadata, - Column('id', String(length=32), nullable=False, primary_key=True), - Column('company_id', ForeignKey('company.id', - name='person_company_id_fkey', - match='FULL', onupdate='RESTRICT', ondelete='RESTRICT', - deferrable=True, initially='DEFERRED' - ) - ) - ) - company = Table('company', metadata, - Column('id', String(length=32), nullable=False, primary_key=True), - Column('name', String(length=255)), - Column('industry_id', ForeignKey('industry.id', - name='company_industry_id_fkey', - onupdate='CASCADE', ondelete='CASCADE', - deferrable=False, # PG default - initially='IMMEDIATE' # PG default - ) - ) - ) - industry = Table('industry', metadata, - Column('id', Integer(), nullable=False, primary_key=True), - Column('name', String(length=255)) - ) - fk_ref = { - 'person_company_id_fkey': { - 'name': 'person_company_id_fkey', - 'constrained_columns': ['company_id'], - 'referred_columns': ['id'], - 'referred_table': 'company', - 'referred_schema': None, - 'options': { - 'onupdate': 'RESTRICT', - 'deferrable': True, - 'ondelete': 'RESTRICT', - 'initially': 'DEFERRED', - 'match': 'FULL' - } - }, - 'company_industry_id_fkey': { - 'name': 'company_industry_id_fkey', - 'constrained_columns': ['industry_id'], - 'referred_columns': ['id'], - 'referred_table': 'industry', - 'referred_schema': None, - 'options': { - 'onupdate': 'CASCADE', - 'deferrable': None, - 'ondelete': 'CASCADE', - 'initially': None, - 'match': None - } - } - } - try: - connection = testing.db.connect() - industry.create() - company.create() - person.create() - inspector = Inspector.from_engine(connection) - fks = inspector.get_foreign_keys('person') + \ - inspector.get_foreign_keys('company') - for fk in fks: - ref = fk_ref[fk['name']] - for key, val in fk.items(): - eq_(val, ref[key]) - finally: - person.drop() - company.drop() - industry.drop() diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 1f2c1e94b..58f34d5d0 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -5,6 +5,7 @@ from sqlalchemy.testing.assertions import eq_, assert_raises, \ AssertsCompiledSQL, ComparesTables from sqlalchemy.testing import engines, fixtures from sqlalchemy import testing +from sqlalchemy import inspect from sqlalchemy import Table, Column, select, MetaData, text, Integer, \ String, Sequence, ForeignKey, join, Numeric, \ PrimaryKeyConstraint, DateTime, tuple_, Float, BigInteger, \ @@ -427,6 +428,70 @@ class ReflectionTest(fixtures.TestBase): eq_(ind, [{'unique': False, 'column_names': ['y'], 'name': 'idx1'}]) conn.close() + @testing.provide_metadata + def test_foreign_key_option_inspection(self): + metadata = self.metadata + Table('person', metadata, + Column('id', String(length=32), nullable=False, primary_key=True), + Column('company_id', ForeignKey('company.id', + name='person_company_id_fkey', + match='FULL', onupdate='RESTRICT', ondelete='RESTRICT', + deferrable=True, initially='DEFERRED' + ) + ) + ) + Table('company', metadata, + Column('id', String(length=32), nullable=False, primary_key=True), + Column('name', String(length=255)), + Column('industry_id', ForeignKey('industry.id', + name='company_industry_id_fkey', + onupdate='CASCADE', ondelete='CASCADE', + deferrable=False, # PG default + initially='IMMEDIATE' # PG default + ) + ) + ) + Table('industry', metadata, + Column('id', Integer(), nullable=False, primary_key=True), + Column('name', String(length=255)) + ) + fk_ref = { + 'person_company_id_fkey': { + 'name': 'person_company_id_fkey', + 'constrained_columns': ['company_id'], + 'referred_columns': ['id'], + 'referred_table': 'company', + 'referred_schema': None, + 'options': { + 'onupdate': 'RESTRICT', + 'deferrable': True, + 'ondelete': 'RESTRICT', + 'initially': 'DEFERRED', + 'match': 'FULL' + } + }, + 'company_industry_id_fkey': { + 'name': 'company_industry_id_fkey', + 'constrained_columns': ['industry_id'], + 'referred_columns': ['id'], + 'referred_table': 'industry', + 'referred_schema': None, + 'options': { + 'onupdate': 'CASCADE', + 'deferrable': None, + 'ondelete': 'CASCADE', + 'initially': None, + 'match': None + } + } + } + metadata.create_all() + inspector = inspect(testing.db) + fks = inspector.get_foreign_keys('person') + \ + inspector.get_foreign_keys('company') + for fk in fks: + eq_(fk, fk_ref[fk['name']]) + class CustomTypeReflectionTest(fixtures.TestBase): class CustomType(object): diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py index c36052781..e7baa9d56 100644 --- a/test/engine/test_reflection.py +++ b/test/engine/test_reflection.py @@ -647,9 +647,9 @@ class ReflectionTest(fixtures.TestBase, ComparesTables): meta2 = MetaData() meta2.reflect(testing.db) for fk in meta2.tables['addresses'].foreign_keys: - ref = locals()[fk.name] + ref = addresses_user_id_fkey for attr in test_attrs: - assert getattr(fk, attr) == getattr(ref, attr) + eq_(getattr(fk, attr), getattr(ref, attr)) def test_pks_not_uniques(self): """test that primary key reflection not tripped up by unique |