summaryrefslogtreecommitdiff
path: root/test/ext
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-02-08 21:24:13 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2014-02-08 21:24:13 -0500
commitee88e648f7a56ef76426957a5344639ab9954d9d (patch)
treee64a9406e93ab44b937c04568a752d9083a396d7 /test/ext
parent5c188f6c1ce85eaace27f052bfd1a14f74f6a659 (diff)
downloadsqlalchemy-ee88e648f7a56ef76426957a5344639ab9954d9d.tar.gz
- Fixed bug where the :class:`.AutomapBase` class of the
new automap extension would fail if classes were pre-arranged in single or potentially joined inheritance patterns. The repaired joined inheritance issue could also potentially apply when using :class:`.DeferredReflection` as well.
Diffstat (limited to 'test/ext')
-rw-r--r--test/ext/test_automap.py65
1 files changed, 65 insertions, 0 deletions
diff --git a/test/ext/test_automap.py b/test/ext/test_automap.py
index 9db85879d..3a2d4d31c 100644
--- a/test/ext/test_automap.py
+++ b/test/ext/test_automap.py
@@ -4,6 +4,8 @@ from sqlalchemy.ext.automap import automap_base
from sqlalchemy.orm import relationship, interfaces, backref
from sqlalchemy.ext.automap import generate_relationship
from sqlalchemy.testing.mock import Mock, call
+from sqlalchemy import Column, String, Table, Integer, ForeignKey
+from sqlalchemy import testing
class AutomapTest(fixtures.MappedTest):
@classmethod
@@ -144,3 +146,66 @@ class AutomapTest(fixtures.MappedTest):
(Base, interfaces.MANYTOONE, "users"),
(Base, interfaces.ONETOMANY, "addresses_collection"),
])
+
+
+class AutomapInhTest(fixtures.MappedTest):
+ @classmethod
+ def define_tables(cls, metadata):
+ Table('single', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('type', String(10))
+ )
+
+ Table('joined_base', metadata,
+ Column('id', Integer, primary_key=True),
+ Column('type', String(10))
+ )
+
+ Table('joined_inh', metadata,
+ Column('id', Integer, ForeignKey('joined_base.id'), primary_key=True),
+ )
+
+ FixtureTest.define_tables(metadata)
+
+ def test_single_inheritance_reflect(self):
+ Base = automap_base()
+
+ class Single(Base):
+ __tablename__ = 'single'
+
+ type = Column(String)
+
+ __mapper_args__ = {"polymorphic_identity": "u0",
+ "polymorphic_on": type}
+
+ class SubUser1(Single):
+ __mapper_args__ = {"polymorphic_identity": "u1"}
+
+ class SubUser2(Single):
+ __mapper_args__ = {"polymorphic_identity": "u2"}
+
+ Base.prepare(engine=testing.db, reflect=True)
+
+ assert SubUser2.__mapper__.inherits is Single.__mapper__
+
+ def test_joined_inheritance_reflect(self):
+ Base = automap_base()
+
+ class Joined(Base):
+ __tablename__ = 'joined_base'
+
+ type = Column(String)
+
+ __mapper_args__ = {"polymorphic_identity": "u0",
+ "polymorphic_on": type}
+
+ class SubJoined(Joined):
+ __tablename__ = 'joined_inh'
+ __mapper_args__ = {"polymorphic_identity": "u1"}
+
+
+ Base.prepare(engine=testing.db, reflect=True)
+
+ assert SubJoined.__mapper__.inherits is Joined.__mapper__
+
+