]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
more testcases for propogation with mixins in declarative
authorChris Withers <chris@simplistix.co.uk>
Fri, 9 Apr 2010 16:32:05 +0000 (17:32 +0100)
committerChris Withers <chris@simplistix.co.uk>
Fri, 9 Apr 2010 16:32:05 +0000 (17:32 +0100)
test/ext/test_declarative.py

index 67e650c34f5542facaadfc3638805015005af9c8..c0094b5ccd397eafd10f1808419098849d23337c 100644 (file)
@@ -2209,3 +2209,84 @@ class DeclarativeMixinTest(DeclarativeTestBase):
         assert col.table is not None
         
         eq_(MyModel.__mapper__.always_refresh,True)
+
+    def test_single_table_no_propogation(self):
+
+        class IdColumn:
+            id = Column(Integer, primary_key=True)
+
+        class BaseType(Base, IdColumn):
+            __tablename__ = 'base'
+            discriminator = Column('python_type', String(50))
+            __mapper_args__= dict(polymorphic_on=discriminator)
+            value = Column(Integer())
+
+        class SpecificType1(BaseType):
+            __mapper_args__ = dict(polymorphic_identity='type1')
+
+        class SpecificType2(BaseType):
+            __mapper_args__ = dict(polymorphic_identity='type2')
+
+    def test_joined_table_propogation(self):
+
+        class IdColumn:
+            id = Column(Integer, primary_key=True) 
+    
+        class BaseType(Base, IdColumn):
+            __tablename__ = 'base'
+            discriminator = Column('python_type', String(50))
+            __mapper_args__= dict(polymorphic_on=discriminator)
+            value = Column(Integer())  
+
+        class SpecificType1(BaseType):
+            __tablename__ = 'type1'
+            __mapper_args__ = dict(polymorphic_identity='type1')
+
+        class SpecificType2(BaseType):
+            __tablename__ = 'type2'
+            __mapper_args__ = dict(polymorphic_identity='type2')
+
+    def test_tablename_propogation(self):
+        # ie: we want joined table
+        class TableNameMixin:
+            @classproperty
+            def __tablename__(cls):
+                return cls.__name__.lower()
+
+        class BaseType(Base, TableNameMixin):
+            discriminator = Column('python_type', String(50))
+            __mapper_args__= dict(polymorphic_on=discriminator)
+            value = Column(Integer())  
+            id = Column(Integer, primary_key=True) 
+
+        class SpecificType1(BaseType):
+            __mapper_args__ = dict(polymorphic_identity='type1')
+            id = Column(Integer, primary_key=True) 
+
+        class SpecificType2(BaseType):
+            __mapper_args__ = dict(polymorphic_identity='type2')
+            id = Column(Integer, primary_key=True) 
+            
+    def test_tablename_no_propogation(self):
+        # ie: we want single table
+        
+        class TableNameMixin:
+            @classproperty
+            def __tablename__(cls):
+                return cls.__name__.lower()
+
+        class BaseType(Base, TableNameMixin):
+            __tablename__ = 'base'
+            discriminator = Column('python_type', String(50))
+            __mapper_args__= dict(polymorphic_on=discriminator)
+            id = Column(Integer, primary_key=True) 
+            value = Column(Integer())  
+
+        class SpecificType1(BaseType):
+            __tablename__ = 'type1'
+            __mapper_args__ = dict(polymorphic_identity='type1')
+
+        class SpecificType2(BaseType):
+            __tablename__ = 'type2'
+            __mapper_args__ = dict(polymorphic_identity='type2')
+