def test_reset_database_not_exists(self): dbname = 'testresetdb' PSQL.reset_database(dbname) time.sleep(4) self.assertTrue(PSQL.database_exists(dbname)) PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))
def test_create_database(self): dbname = 'testdb' self.assertFalse(PSQL.database_exists(dbname)) PSQL.create_database(dbname) time.sleep(4) self.assertTrue(PSQL.database_exists(dbname)) PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))
def test_drop_database(self): dbname = "testdropdb" self.assertFalse(PSQL.database_exists(dbname)) PSQL.create_database(dbname) time.sleep(4) self.assertTrue(PSQL.database_exists(dbname)) # dropdb PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))
def test_create_database_already_exists(self): dbname = 'testdupdb' self.assertFalse(PSQL.database_exists(dbname)) PSQL.create_database(dbname) time.sleep(4) self.assertTrue(PSQL.database_exists(dbname)) with self.assertRaises(PSQLException) as cm: PSQL.create_database(dbname) PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))
def test_reset_database_exists(self): dbname = 'testresetdb2' PSQL.create_database(dbname) time.sleep(4) PSQL.run_sql_command(sql_cmd="CREATE TABLE testresettable(i int)", dbname=dbname) output = PSQL.run_sql_command(sql_cmd="SELECT * FROM testresettable", dbname=dbname) self.assertIsNotNone(re.search('0 rows', output)) PSQL.reset_database(dbname) out_file = os.path.join( os.path.dirname(inspect.getfile(self.__class__)), 'test_reset_database_exists.out') self.assertFalse(os.path.exists(out_file)) PSQL.run_sql_command(sql_cmd="SELECT * FROM testresettable", dbname=dbname, out_file=out_file) self.assertTrue(os.path.exists(out_file)) # stdout should be none with open(out_file, 'r') as f: output = f.read() self.assertIsNotNone(re.search('relation.*does not exist', output)) os.remove(out_file) self.assertFalse(os.path.exists(out_file)) PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))
def setUpClass(cls): dbs = ['testdb', 'testdupdb', 'testdropdb', 'testresetdb', 'testresetdb2'] for db in dbs: if PSQL.database_exists(db): PSQL.drop_database(db) curr_dir = os.path.dirname(inspect.getfile(cls)) for filename in os.listdir(curr_dir): if fnmatch.fnmatch(filename, "*.out"): os.remove(os.path.join(curr_dir, filename))
def setUpClass(cls): dbs = [ 'testdb', 'testdupdb', 'testdropdb', 'testresetdb', 'testresetdb2' ] for db in dbs: if PSQL.database_exists(db): PSQL.drop_database(db) curr_dir = os.path.dirname(inspect.getfile(cls)) for filename in os.listdir(curr_dir): if fnmatch.fnmatch(filename, "*.out"): os.remove(os.path.join(curr_dir, filename))
def test_reset_database_exists(self): dbname = 'testresetdb2' PSQL.create_database(dbname) time.sleep(4) PSQL.run_sql_command(sql_cmd = "CREATE TABLE testresettable(i int)", dbname = dbname) output = PSQL.run_sql_command(sql_cmd = "SELECT * FROM testresettable", dbname = dbname) self.assertIsNotNone(re.search('0 rows', output)) PSQL.reset_database(dbname) out_file = os.path.join(os.path.dirname(inspect.getfile(self.__class__)),'test_reset_database_exists.out') self.assertFalse(os.path.exists(out_file)) PSQL.run_sql_command(sql_cmd = "SELECT * FROM testresettable", dbname = dbname, out_file = out_file) self.assertTrue(os.path.exists(out_file)) # stdout should be none with open(out_file, 'r') as f: output = f.read() self.assertIsNotNone(re.search('relation.*does not exist', output)) os.remove(out_file) self.assertFalse(os.path.exists(out_file)) PSQL.drop_database(dbname) time.sleep(4) self.assertFalse(PSQL.database_exists(dbname))