예제 #1
0
 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))
예제 #2
0
 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))
예제 #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_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))
예제 #5
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))
예제 #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_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))
예제 #8
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))
예제 #9
0
    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))
예제 #10
0
    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))
예제 #11
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))