summaryrefslogtreecommitdiff
path: root/test/engine/test_reflection.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 15:54:28 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-28 15:54:28 -0500
commit96dce7686c6a32ab03ce2ccaabb7a9b4ff0fe56b (patch)
tree9468e4f0c5ee4748a21c2a2aaba7d1ddb0a74db0 /test/engine/test_reflection.py
parentb7f7ed210501a405938bf55e08a47e35674f0247 (diff)
downloadsqlalchemy-96dce7686c6a32ab03ce2ccaabb7a9b4ff0fe56b.tar.gz
- [feature] New reflection feature "autoload_replace";
when set to False on Table, the Table can be autoloaded without existing columns being replaced. Allows more flexible chains of Table construction/reflection to be constructed, including that it helps with combining Declarative with table reflection. See the new example on the wiki. [ticket:2356] - [bug] Improved the API for add_column() such that if the same column is added to its own table, an error is not raised and the constraints don't get doubled up. Also helps with some reflection/declarative patterns. [ticket:2356]
Diffstat (limited to 'test/engine/test_reflection.py')
-rw-r--r--test/engine/test_reflection.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/test/engine/test_reflection.py b/test/engine/test_reflection.py
index e32c868d6..13c8ee0ef 100644
--- a/test/engine/test_reflection.py
+++ b/test/engine/test_reflection.py
@@ -160,6 +160,27 @@ class ReflectionTest(fixtures.TestBase, ComparesTables):
set(['z'])
)
+ m4 = MetaData()
+ old_z = Column('z', String, primary_key=True)
+ old_y = Column('y', String)
+ old_q = Column('q', Integer)
+ t4 = Table('t', m4, old_z, old_q)
+ eq_(t4.primary_key.columns, (t4.c.z, ))
+ t4 = Table('t', m4, old_y,
+ extend_existing=True,
+ autoload=True,
+ autoload_replace=False,
+ autoload_with=testing.db)
+ eq_(
+ set(t4.columns.keys()),
+ set(['x', 'y', 'z', 'q', 'id'])
+ )
+ eq_(t4.primary_key.columns, (t4.c.id, ))
+ assert t4.c.z is old_z
+ assert t4.c.y is old_y
+ assert t4.c.z.type._type_affinity is String
+ assert t4.c.q is old_q
+
@testing.emits_warning(r".*omitted columns")
@testing.provide_metadata
def test_include_columns_indexes(self):
@@ -182,6 +203,27 @@ class ReflectionTest(fixtures.TestBase, ComparesTables):
assert len(t2.indexes) == 2
@testing.provide_metadata
+ def test_autoload_replace(self):
+ a = Table('a', self.metadata, Column('id', Integer, primary_key=True))
+ b = Table('b', self.metadata, Column('id', Integer, primary_key=True),
+ Column('a_id', Integer))
+ self.metadata.create_all()
+
+ m2 = MetaData()
+ b2 = Table('b', m2, Column('a_id', Integer, sa.ForeignKey('a.id')))
+ a2 = Table('a', m2, autoload=True, autoload_with=testing.db)
+ b2 = Table('b', m2, extend_existing=True, autoload=True,
+ autoload_with=testing.db,
+ autoload_replace=False)
+
+ assert b2.c.id is not None
+ assert b2.c.a_id.references(a2.c.id)
+ eq_(len(b2.constraints), 2)
+
+ def test_autoload_replace_arg(self):
+ Table('t', MetaData(), autoload_replace=False)
+
+ @testing.provide_metadata
def test_autoincrement_col(self):
"""test that 'autoincrement' is reflected according to sqla's policy.