Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class BaseDBTest(base.BaseTestCase):
- ADDRESS_MATCHER = re.compile("(.*://.*?/)(.*)")
- """
- Base class for tests that aim to test the interaction with the
- database in a way as similar as possible to the real world scenario.
- For this purpose sqlite is not enough.
- A test database is created in the setup. The name is using a random
- uuid to guarantee better isolation
- """
- def setUp(self, neutron_conf_path):
- super(BaseDBTest, self).setUp()
- cfg.CONF(['--config-file', neutron_conf_path])
- connection = cfg.CONF.database.connection
- match = self.ADDRESS_MATCHER.search(connection)
- address, db_name = match.groups()
- cfg.CONF.set_override('connection', address, group='database')
- self.engine = db_api.get_engine()
- self.addCleanup(self.drop_db, db_name)
- self.create_db(db_name)
- import ipdb;ipdb.set_trace()
- model_base.BASEV2.metadata.create_all(self.engine)
- def create_db(self, db_name):
- with self.engine.connect() as conn:
- conn.execute("CREATE DATABASE %s" % db_name)
- conn.execute("USE %s" % db_name)
- def drop_db(self, db_name):
- with self.engine.connect() as conn:
- conn.execute("DROP DATABASE %s" % db_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement