Exemplo n.º 1
0
 def setUp(self):
     super(DBFixture, self).setUp()
     self.engine = db_api.get_engine()
     self.engine.connect()
     self.dbfixture = SQLAlchemyFixture(engine=self.engine, env={"StoreStateMock": StoreState})
     self.data = self.dbfixture.data(StoreStateMock)
     self.session = db_api.get_session()
     BASE.metadata.create_all(bind=self.engine)
     self.data.setup()
     self.addCleanup(self.data.teardown)
Exemplo n.º 2
0
    def test_db_create_table(self):

        import sqlalchemy as sa

        class SampleModel(BASE, models.TableNameMixin, models.HasIdMixin):

            hostname = sa.Column(sa.String(252), nullable=False, unique=True)
            lan_ip = sa.Column(sa.String(16), nullable=False, unique=True)

        CONF.set_default('connection', self.TESTDB_URI, 'database')
        BASE.metadata.create_all(get_engine())
        session = get_session()
        with session.begin(subtransactions=True):
            obj = SampleModel()
            obj.hostname = 'hostname'
            obj.lan_ip = '1.2.3.4'
            session.add(obj)

        retval = dict(session.query(SampleModel).one())
        self.assertEqual(retval['hostname'], obj.hostname)
        self.assertEqual(retval['lan_ip'], obj.lan_ip)
Exemplo n.º 3
0
def get_session(*args, **kwargs):
    return db_api.get_session(*args, **kwargs)
Exemplo n.º 4
0
 def test_db_init(self):
     from sqlalchemy.orm.session import Session
     CONF.set_default('connection', self.TESTDB_URI, 'database')
     self.assertIsInstance(get_session(), Session)