Advertisement
Guest User

Untitled

a guest
Oct 13th, 2014
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.29 KB | None | 0 0
  1. class BaseDBTest(base.BaseTestCase):
  2.     ADDRESS_MATCHER = re.compile("(.*://.*?/)(.*)")
  3.     """
  4.    Base class for tests that aim to test the interaction with the
  5.    database in a way as similar as possible to the real world scenario.
  6.    For this purpose sqlite is not enough.
  7.  
  8.    A test database is created in the setup. The name is using a random
  9.    uuid to guarantee better isolation
  10.    """
  11.     def setUp(self, neutron_conf_path):
  12.         super(BaseDBTest, self).setUp()
  13.         cfg.CONF(['--config-file', neutron_conf_path])
  14.  
  15.         connection = cfg.CONF.database.connection
  16.         match = self.ADDRESS_MATCHER.search(connection)
  17.         address, db_name = match.groups()
  18.         cfg.CONF.set_override('connection', address, group='database')
  19.  
  20.         self.engine = db_api.get_engine()
  21.         self.addCleanup(self.drop_db, db_name)
  22.         self.create_db(db_name)
  23.         import ipdb;ipdb.set_trace()
  24.         model_base.BASEV2.metadata.create_all(self.engine)
  25.  
  26.     def create_db(self, db_name):
  27.         with self.engine.connect() as conn:
  28.             conn.execute("CREATE DATABASE %s" % db_name)
  29.             conn.execute("USE %s" % db_name)
  30.  
  31.     def drop_db(self, db_name):
  32.         with self.engine.connect() as conn:
  33.             conn.execute("DROP DATABASE %s" % db_name)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement