Beispiel #1
0
    def setUp(self, connection_string='sqlite://'):
        super(OctaviaDBTestBase, self).setUp()
        # NOTE(blogan): doing this for now because using the engine and
        # session set up in the fixture for test_base.DbTestCase does not work
        # with the API functional tests.  Need to investigate more if this
        # becomes a problem
        conf = self.useFixture(oslo_fixture.Config(config.cfg.CONF))
        conf.config(group="database", connection=connection_string)

        # We need to get our own Facade so that the file backed sqlite tests
        # don't use the _FACADE singleton. Some tests will use in-memory
        # sqlite, some will use a file backed sqlite.
        if 'sqlite:///' in connection_string:
            facade = db_session.EngineFacade.from_config(cfg.CONF,
                                                         sqlite_fk=True)
            engine = facade.get_engine()
            self.session = facade.get_session(expire_on_commit=True,
                                              autocommit=True)
        else:
            engine = db_api.get_engine()
            self.session = db_api.get_session()

        base_models.BASE.metadata.create_all(engine)
        self._seed_lookup_tables(self.session)

        def clear_tables():
            """Unregister all data models."""
            base_models.BASE.metadata.drop_all(engine)
            # If we created a file, clean it up too
            if 'sqlite:///' in connection_string:
                os.remove(connection_string.replace('sqlite:///', ''))

        self.addCleanup(clear_tables)
Beispiel #2
0
    def setUp(self):
        super(OctaviaDBTestBase, self).setUp()
        # NOTE(blogan): doing this for now because using the engine and
        # session set up in the fixture for test_base.DbTestCase does not work
        # with the API functional tests.  Need to investigate more if this
        # becomes a problem
        cfg.CONF.register_opts(db_options.database_opts, 'database')
        cfg.CONF.set_override('connection', 'sqlite://', group='database')
        # needed for closure
        engine = db_api.get_engine()
        session = db_api.get_session()
        base_models.BASE.metadata.create_all(engine)
        self._seed_lookup_tables(session)

        def clear_tables():
            """Unregister all data models."""
            base_models.BASE.metadata.drop_all(engine)

        self.addCleanup(clear_tables)

        self.session = session
Beispiel #3
0
    def setUp(self):
        super(OctaviaDBTestBase, self).setUp()
        # NOTE(blogan): doing this for now because using the engine and
        # session set up in the fixture for test_base.DbTestCase does not work
        # with the API functional tests.  Need to investigate more if this
        # becomes a problem
        cfg.CONF.register_opts(db_options.database_opts, 'database')
        cfg.CONF.set_override('connection', 'sqlite://', group='database')
        # needed for closure
        engine = db_api.get_engine()
        session = db_api.get_session()
        base_models.BASE.metadata.create_all(engine)
        self._seed_lookup_tables(session)

        def clear_tables():
            """Unregister all data models."""
            base_models.BASE.metadata.drop_all(engine)

        self.addCleanup(clear_tables)

        self.session = session