示例#1
0
    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))
示例#2
0
 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))
示例#3
0
 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))
示例#4
0
 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))
示例#5
0
 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))
示例#6
0
 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))
示例#7
0
    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))