Example #1
0
    def testReentrance(self):
        class Test(self.declarative_base):
            __tablename__ = 'Test'
            id = Column(Integer, primary_key=True)
            field = Column(String)

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum1 = SADatum('Test', 'id')
        SADatum.cleanup()

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum1 = SADatum('Test', 'id')
Example #2
0
 def testWithSchemaOnly1(self):
     SADatum = self.SADatum = newSADatum(self.metadata)
     try:
         SADatum('Test', 'id', field='test')
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual("Test is not defined in the metadata", e.args[0])
Example #3
0
 def testPrimaryKey4(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True)
         )
     SADatum = newSADatum(self.metadata)
     datum = SADatum('Test')
     self.assertEqual(('id', ), datum._tableau_id_fields)
Example #4
0
 def testAuxPropertyWithSchemaOnly(self):
     table = Table('Test', self.metadata,
                   Column('id', Integer, primary_key=True),
                   Column('field', String))
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(table, 'id', field='test')
     datum._aux = 1
     self.assertEqual(1, datum._aux)
Example #5
0
 def testWithSchemaOnly3(self):
     table = Table('Test', self.metadata,
                   Column('id', Integer, primary_key=True),
                   Column('field', String))
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(table, 'id', field='test')
     self.assertEqual('Test', datum._tableau_schema)
     self.assertEqual(table, datum._tableau_table)
Example #6
0
    def testReentrance(self):
        class Test(self.declarative_base):
            __tablename__ = 'Test'
            id = Column(Integer, primary_key=True)
            field = Column(String)
        SADatum = self.SADatum = newSADatum(self.metadata)
        datum1 = SADatum(
            'Test',
            'id'
            )
        SADatum.cleanup()

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum1 = SADatum(
            'Test',
            'id'
            )
Example #7
0
    def testAuxPropertyWithDeclarative(self):
        class Test(self.declarative_base):
            __tablename__ = 'Test'
            id = Column(Integer, primary_key=True)
            field = Column(String)

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum = SADatum('Test', 'id', field='test')
        datum._aux = 1
        self.assertEqual(1, datum._aux)
Example #8
0
 def testPrimaryKey1(self):
     table = Table('Test', self.metadata,
                   Column('id', Integer, primary_key=True))
     SADatum = self.SADatum = newSADatum(self.metadata)
     try:
         SADatum('Test', 'oops')
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual(
             "id_fields does not match to the table definition ([oops] != [id])",
             e.args[0])
Example #9
0
 def testWithSchemaOnly1(self):
     SADatum = newSADatum(self.metadata)
     try:
         SADatum(
             'Test',
             'id',
             field='test'
             )
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual("Test is not defined in the metadata", e.args[0])
Example #10
0
    def testWithDeclarative2(self):
        class Test(self.declarative_base):
            __tablename__ = 'Test'
            id = Column(Integer, primary_key=True)
            field = Column(String)

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum = SADatum('Test', 'id', field='test')
        self.assertEqual('Test', datum._tableau_schema)
        self.assertEqual(Test.__table__, datum._tableau_table)
        self.assertEqual('test', datum.field)
Example #11
0
    def testWithDeclarative1(self):
        class Test(self.declarative_base):
            __tablename__ = 'Oops'
            id = Column(Integer, primary_key=True)

        SADatum = self.SADatum = newSADatum(self.metadata)
        try:
            SADatum('Test', 'id', field='test')
            self.fail("No expection raised")
        except ValueError, e:
            self.assertEqual("Test is not defined in the metadata", e.args[0])
Example #12
0
    def testIfDeclarativeIsAddableToSession(self):
        class Foo(self.declarative_base):
            __tablename__ = 'Foo'
            id = Column(Integer, primary_key=True)
            field = Column(String)
            bars = relationship('Bar')
            def some_model_specific_method(self):
              return self.field

        class Bar(self.declarative_base):
            __tablename__ = 'Bar'
            id = Column(Integer, primary_key=True)
            type = Column(String)
            foo_id = Column(Integer, ForeignKey('Foo.id'))
            __mapper_args__ = { 'polymorphic_on': type }

        class Foobar(Bar):
            __tablename__ = 'Foobar'
            __mapper_args__ = {'polymorphic_identity': 'foobar'}
            id = Column(Integer, ForeignKey('Bar.id'), primary_key=True)

        SADatum = newSADatum(self.metadata, self.declarative_base)
        datum = SADatum(
            'Foo',
            auto('id'),
            field='test',
            bars=one_to_many([
                SADatum(
                    'Bar',
                    auto('id')
                    ),
                SADatum(
                    'Foobar',
                    auto('id')
                    )
                ],
                'foo_id'
                )
            )
        self.assertEqual('Foo', datum._tableau_schema)
        self.assertEqual(Foo.__table__, datum._tableau_table)
        self.assertEqual('test', datum.field)
        self.assertIsInstance(datum, Foo)
        self.assertEqual('test', datum.some_model_specific_method())
        self.assertIsInstance(datum.bars[0], Bar)
        self.assertIsInstance(datum.bars[1], Bar)
        engine = create_engine('sqlite+pysqlite:///', echo=True)
        session = sessionmaker(engine)()
        self.metadata.create_all(engine)
        session.add(datum)
        session.flush()
        self.assertEqual(1, datum.id)
        self.assertEqual(1, datum.bars[0].id)
        self.assertEqual(2, datum.bars[1].id)
Example #13
0
 def testManyToOne3(self):
     metadata = MetaData()
     Table('Schema', metadata, Column('id', Integer, primary_key=True),
           Column('parent_id', Integer))
     SADatum = self.SADatum = newSADatum(metadata)
     a = SADatum('Schema',
                 'id',
                 id=1,
                 parent=many_to_one(Datum('Foo', 'id', id=1), 'parent_id'))
     suite = DataSuite()
     DataWalker(suite)(a)
     self.assertEqual(1, a._tableau_fields['parent'].render())
Example #14
0
 def testAuxPropertyWithDeclarative(self):
     class Test(self.declarative_base):
         __tablename__ = 'Test'
         id = Column(Integer, primary_key=True)
         field = Column(String)
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(
         'Test',
         'id',
         field='test'
         )
     datum._aux = 1
     self.assertEqual(1, datum._aux)
Example #15
0
 def testAuxPropertyWithSchemaOnly(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True),
         Column('field', String)
         )
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(
         table,
         'id',
         field='test'
         )
     datum._aux = 1
     self.assertEqual(1, datum._aux)
Example #16
0
 def testDefaultValue(self):
     table = Table('Test', self.metadata,
                   Column('id', Integer, primary_key=True),
                   Column('field', String, default='foo'))
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum1 = SADatum('Test', 'id')
     datum2 = SADatum('Test', 'id', field='test')
     self.assertEqual('Test', datum1._tableau_schema)
     self.assertEqual(table, datum1._tableau_table)
     self.assertEqual('foo', datum1.field)
     self.assertEqual('Test', datum2._tableau_schema)
     self.assertEqual(table, datum2._tableau_table)
     self.assertEqual('test', datum2.field)
Example #17
0
 def testDefaultValueFunction(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True),
         Column('field', String, default=lambda : 'foo', onupdate=lambda : "update")
         )
     SADatum = newSADatum(self.metadata)
     datum1 = SADatum(
         'Test',
         'id'
         )
     self.assertEqual('Test', datum1._tableau_schema)
     self.assertEqual(table, datum1._tableau_table)
     self.assertEqual('foo', datum1.field)
Example #18
0
 def testWithSchemaOnly3(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True),
         Column('field', String)
         )
     SADatum = newSADatum(self.metadata)
     datum = SADatum(
         table,
         'id',
         field='test'
         )
     self.assertEqual('Test', datum._tableau_schema)
     self.assertEqual(table, datum._tableau_table)
Example #19
0
 def testPrimaryKey3(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True)
         )
     SADatum = newSADatum(self.metadata)
     try:
         SADatum(
             'Test',
             ('id1', 'id2'),
             )
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual("id_fields does not match to the table definition ([id1,id2] != [id])", e.args[0])
Example #20
0
 def testWithDeclarative2(self):
     class Test(self.declarative_base):
         __tablename__ = 'Test'
         id = Column(Integer, primary_key=True)
         field = Column(String)
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(
         'Test',
         'id',
         field='test'
         )
     self.assertEqual('Test', datum._tableau_schema)
     self.assertEqual(Test.__table__, datum._tableau_table)
     self.assertEqual('test', datum.field)
Example #21
0
 def testWithDeclarative1(self):
     class Test(self.declarative_base):
         __tablename__ = 'Oops'
         id = Column(Integer, primary_key=True)
     SADatum = newSADatum(self.metadata, self.declarative_base)
     try:
         SADatum(
             'Test',
             'id',
             field='test'
             )
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual("Test is not defined in the metadata", e.args[0])
Example #22
0
    def testIfDeclarativeIsWalkable(self):
        class Test(self.declarative_base):
            __tablename__ = 'Test'
            id = Column(Integer, primary_key=True)
            field = Column(String)

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum = SADatum('Test', auto('id'), field='test')
        self.assertEqual('Test', datum._tableau_schema)
        self.assertEqual(Test.__table__, datum._tableau_table)
        self.assertEqual('test', datum.field)
        suite = DataSuite()
        DataWalker(suite)(datum)
        self.assertEqual(1, datum.id)
Example #23
0
 def testWithDeclarative2(self):
     table = Table('Test', self.metadata, Column('id', Integer, primary_key=True))
     class Test(self.declarative_base):
         __tablename__ = 'Oops'
         id = Column(Integer, primary_key=True)
     SADatum = newSADatum(self.metadata, self.declarative_base)
     try:
         SADatum(
             'Test',
             'id',
             field='test'
             )
         self.fail("No expection raised")
     except ValueError, e:
         self.assertEqual("declarative class for Test is not in the class registry", e.args[0])
Example #24
0
 def testIfDeclarativeIsWalkable(self):
     class Test(self.declarative_base):
         __tablename__ = 'Test'
         id = Column(Integer, primary_key=True)
         field = Column(String)
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum(
         'Test',
         auto('id'),
         field='test'
         )
     self.assertEqual('Test', datum._tableau_schema)
     self.assertEqual(Test.__table__, datum._tableau_table)
     self.assertEqual('test', datum.field)
     suite = DataSuite()
     DataWalker(suite)(datum)
     self.assertEqual(1, datum.id)
Example #25
0
 def testManyToOne3(self):
     metadata = MetaData()
     Table('Schema', metadata,
         Column('id', Integer, primary_key=True),
         Column('parent_id', Integer)
         )
     SADatum = newSADatum(metadata)
     a = SADatum(
         'Schema',
         'id',
         id=1,
         parent=many_to_one(
             Datum('Foo', 'id', id=1),
             'parent_id'
             )
         )
     suite = DataSuite()
     DataWalker(suite)(a)
     self.assertEqual(1, a._tableau_fields['parent'].render())
Example #26
0
    def testIfDeclarativeIsAddableToSession(self):
        class Foo(self.declarative_base):
            __tablename__ = 'Foo'
            id = Column(Integer, primary_key=True)
            field = Column(String)
            bars = relationship('Bar')

            def some_model_specific_method(self):
                return self.field

        class Bar(self.declarative_base):
            __tablename__ = 'Bar'
            id = Column(Integer, primary_key=True)
            type = Column(String)
            foo_id = Column(Integer, ForeignKey('Foo.id'))
            __mapper_args__ = {'polymorphic_on': type}

        class Foobar(Bar):
            __tablename__ = 'Foobar'
            __mapper_args__ = {'polymorphic_identity': 'foobar'}
            id = Column(Integer, ForeignKey('Bar.id'), primary_key=True)

        SADatum = self.SADatum = newSADatum(self.metadata)
        datum = SADatum(
            'Foo',
            auto('id'),
            field='test',
            bars=one_to_many(
                [SADatum('Bar', auto('id')),
                 SADatum('Foobar', auto('id'))], 'foo_id'))
        self.assertEqual('Foo', datum._tableau_schema)
        self.assertEqual(Foo.__table__, datum._tableau_table)
        self.assertEqual('test', datum.field)
        self.assertEqual('test', datum.some_model_specific_method())
        engine = create_engine('sqlite+pysqlite:///', echo=True)
        session = sessionmaker(engine)()
        self.metadata.create_all(engine)
        session.add(datum)
        session.flush()
        self.assertEqual(1, datum.id)
        self.assertEqual(1, datum.bars[0].id)
        self.assertEqual(2, datum.bars[1].id)
Example #27
0
 def testDefaultValue(self):
     table = Table('Test', self.metadata,
         Column('id', Integer, primary_key=True),
         Column('field', String, default='foo')
         )
     SADatum = newSADatum(self.metadata)
     datum1 = SADatum(
         'Test',
         'id'
         )
     datum2 = SADatum(
         'Test',
         'id',
         field='test'
         )
     self.assertEqual('Test', datum1._tableau_schema)
     self.assertEqual(table, datum1._tableau_table)
     self.assertEqual('foo', datum1.field)
     self.assertEqual('Test', datum2._tableau_schema)
     self.assertEqual(table, datum2._tableau_table)
     self.assertEqual('test', datum2.field)
Example #28
0
 def testPrimaryKey4(self):
     table = Table('Test', self.metadata,
                   Column('id', Integer, primary_key=True))
     SADatum = self.SADatum = newSADatum(self.metadata)
     datum = SADatum('Test')
     self.assertEqual(('id', ), datum._tableau_id_fields)