def test_save(self): "Test database saving (and reload)." self.dbname1 = dbutil.random_name('test_save_db') self.filename1 = self.dbname1 + ".sql" # Create a new database. dbutil.TESTSERVER.create(self.dbname1, self.SAVE_DIR, self.SAVE_FILE) # Save the database to disk. dbutil.TESTSERVER.save(self.dbname1, self.SAVE_DIR, self.filename1, 'processing_level') # Now reload the file as a new database... self.dbname2 = dbutil.random_name('test_save_db_copy') dbutil.TESTSERVER.create(self.dbname2, self.SAVE_DIR, self.filename1) # and check that it exists. maint_conn = dbutil.TESTSERVER.connect(self.MAINTENANCE_DB, superuser=True) try: maint_conn = dbutil.MaintenanceWrapper(maint_conn) self.assertTrue( maint_conn.exists(self.dbname2), "Saved and reloaded database " + "does not seem to be there.") finally: maint_conn.close()
def test_drop(self): "Test ability to drop a database" self.dbname1 = dbutil.random_name('test_drop_db') # Create a new database. dbutil.TESTSERVER.create(self.dbname1, self.SAVE_DIR, self.SAVE_FILE) # Connect to the newly created database, to make sure it is # there, and to create a pgbouncer pool. conn = dbutil.TESTSERVER.connect(self.dbname1) try: conn = dbutil.ConnectionWrapper(conn) dbname = conn.database_name() self.assertEqual(dbname, self.dbname1) finally: conn.close() # Now drop the database... dbutil.TESTSERVER.drop(self.dbname1) # and make sure it is gone. maint_conn = dbutil.TESTSERVER.connect(self.MAINTENANCE_DB, superuser=True) try: maint_conn = dbutil.MaintenanceWrapper(maint_conn) self.assertFalse(maint_conn.exists(self.dbname1), "Dropped database still seems to be there.") finally: maint_conn.close()
def test_recreate(self): "Test ablility to recreate a database on top of itself" self.dbname1 = dbutil.random_name('test_recreate_db') # Create a new database. dbutil.TESTSERVER.create(self.dbname1, self.SAVE_DIR, self.SAVE_FILE) # Connect to the newly created database, to make sure it is # there, and to create a pgbouncer pool. conn = dbutil.TESTSERVER.connect(self.dbname1) try: conn = dbutil.ConnectionWrapper(conn) dbname = conn.database_name() self.assertEqual(dbname, self.dbname1) finally: conn.close() # Now recreate on top of the existing database... dbutil.TESTSERVER.create(self.dbname1, self.SAVE_DIR, self.SAVE_FILE) # and check that it exists. maint_conn = dbutil.TESTSERVER.connect(self.MAINTENANCE_DB, superuser=True) try: maint_conn = dbutil.MaintenanceWrapper(maint_conn) self.assertTrue(maint_conn.exists(self.dbname1), "Recreated database does not seem to be there.") finally: maint_conn.close()
def test_create(self): "Test database creation and loading" self.dbname1 = dbutil.random_name('test_create_db') # Create a new database. dbutil.TESTSERVER.create(self.dbname1, self.SAVE_DIR, self.SAVE_FILE) # Check if the newly created database exists. maint_conn = dbutil.TESTSERVER.connect(self.MAINTENANCE_DB, superuser=True) try: maint_conn = dbutil.MaintenanceWrapper(maint_conn) self.assertTrue(maint_conn.exists(self.dbname1), "New database does not seem to be there.") finally: maint_conn.close()