def setUp(self): self._provisioning_engine = provision.get_engine( utils.get_connect_string(backend=self.DRIVER, user=self.USERNAME, passwd=self.PASSWORD, database=self.DBNAME)) self._uri = provision.create_database(self._provisioning_engine) super(OpportunisticFixture, self).setUp()
def setUp(self): self._provisioning_engine = provision.get_engine( utils.get_connect_string(backend=self.DRIVER, user=self.USERNAME, passwd=self.PASSWORD, database=self.DBNAME) ) self._uri = provision.create_database(self._provisioning_engine) super(OpportunisticFixture, self).setUp()
def _test_postgresql_opportunistically(self): # Test postgresql database migration walk if not _have_postgresql(self.USER, self.PASSWD, self.DATABASE): self.skipTest("postgresql not available") # add this to the global lists to make reset work with it, it's removed # automatically in tearDown so no need to clean it up here. connect_string = oslodbutils.get_connect_string("postgresql+psycopg2", self.DATABASE, self.USER, self.PASSWD) engine = session.create_engine(connect_string) (user, password, database, host) = get_pgsql_connection_info(urlparse.urlparse(connect_string)) self.engines[database] = engine self.test_databases[database] = connect_string # build a fully populated postgresql database with all the tables self._reset_database(database) self._walk_versions(engine, self.snake_walk, self.downgrade) del (self.engines[database]) del (self.test_databases[database])
def _test_postgresql_opportunistically(self): # Test postgresql database migration walk if not _have_postgresql(self.USER, self.PASSWD, self.DATABASE): self.skipTest("postgresql not available") # add this to the global lists to make reset work with it, it's removed # automatically in tearDown so no need to clean it up here. connect_string = oslodbutils.get_connect_string( "postgresql+psycopg2", self.DATABASE, self.USER, self.PASSWD) engine = session.create_engine(connect_string) (user, password, database, host) = \ get_pgsql_connection_info(urlparse.urlparse(connect_string)) self.engines[database] = engine self.test_databases[database] = connect_string # build a fully populated postgresql database with all the tables self._reset_database(database) self._walk_versions(engine, self.snake_walk, self.downgrade) del(self.engines[database]) del(self.test_databases[database])
def _test_mysql_opportunistically(self): # Test that table creation on mysql only builds InnoDB tables if not _have_mysql(self.USER, self.PASSWD, self.DATABASE): self.skipTest("mysql not available") # add this to the global lists to make reset work with it, it's removed # automatically in tearDown so no need to clean it up here. connect_string = oslodbutils.get_connect_string( "mysql+mysqldb", self.DATABASE, self.USER, self.PASSWD) (user, password, database, host) = \ get_mysql_connection_info(urlparse.urlparse(connect_string)) engine = session.create_engine(connect_string) self.engines[database] = engine self.test_databases[database] = connect_string # build a fully populated mysql database with all the tables self._reset_database(database) self._walk_versions(engine, self.snake_walk, self.downgrade) connection = engine.connect() # sanity check total = connection.execute("SELECT count(*) " "from information_schema.TABLES " "where TABLE_SCHEMA='%(database)s'" % {'database': database}) self.assertTrue(total.scalar() > 0, "No tables found. Wrong schema?") noninnodb = connection.execute("SELECT count(*) " "from information_schema.TABLES " "where TABLE_SCHEMA='%(database)s' " "and ENGINE!='InnoDB' " "and TABLE_NAME!='migrate_version'" % {'database': database}) count = noninnodb.scalar() self.assertEqual(count, 0, "%d non InnoDB tables created" % count) connection.close() del(self.engines[database]) del(self.test_databases[database])
def _get_uri(self): if self._uri is not None: return self._uri credentials = { 'backend': self.DRIVER, 'user': self.USERNAME, 'passwd': self.PASSWORD, 'database': self.DBNAME} if self.DRIVER and not utils.is_backend_avail(**credentials): msg = '%s backend is not available.' % self.DRIVER raise testtools.testcase.TestSkipped(msg) self._provisioning_engine = provision.get_engine( utils.get_connect_string(backend=self.DRIVER, user=self.USERNAME, passwd=self.PASSWORD, database=self.DBNAME) ) self._uri = provision.create_database(self._provisioning_engine) self.addCleanup( provision.drop_database, self._provisioning_engine, self._uri) self.addCleanup(setattr, self, '_uri', None) return self._uri
def test_connect_string_host(self): self.full_credentials['host'] = 'myhost' connect_string = utils.get_connect_string(**self.full_credentials) self.assertEqual(connect_string, 'mysql://*****:*****@myhost/test')
def test_connect_string_sqlite(self): sqlite_credentials = {'backend': 'sqlite', 'database': 'test.db'} connect_string = utils.get_connect_string(**sqlite_credentials) self.assertEqual(connect_string, 'sqlite:///test.db')
def test_connect_string(self): connect_string = utils.get_connect_string(**self.full_credentials) self.assertEqual(connect_string, self.connect_string)
def test_connect_string_host(self): self.full_credentials['host'] = 'myhost' connect_string = utils.get_connect_string(**self.full_credentials) self.assertEqual(connect_string, 'postgresql://*****:*****@myhost/test')
def test_connect_string_host(self): self.full_credentials["host"] = "myhost" connect_string = utils.get_connect_string(**self.full_credentials) self.assertEqual(connect_string, "mysql://*****:*****@myhost/test")
def test_connect_string_sqlite(self): sqlite_credentials = {"backend": "sqlite", "database": "test.db"} connect_string = utils.get_connect_string(**sqlite_credentials) self.assertEqual(connect_string, "sqlite:///test.db")