def test_run_query_empty(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) sqlplus.run_script(script) result = sqlplus.run_query("INSERT INTO test (id, name, age) VALUES " "(2, 'Mignonne', 12);") self.assertEqual((), result)
def test_run_query_empty(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) sqlplus.run_script(script) result = sqlplus.run_query("INSERT INTO test (id, name, age) VALUES " "(2, 'Mignonne', 12);") self.assertEqual((), result)
def test_run_script_error(self): sqlplus = SqlplusCommando(configuration=self.CONFIG) try: sqlplus.run_script("unknown.sql") self.fail('Should have failed') except Exception, e: self.assertTrue("Script 'unknown.sql' was not found" in str(e))
def test_run_script_error(self): sqlplus = SqlplusCommando(configuration=self.CONFIG) try: sqlplus.run_script("unknown.sql") self.fail('Should have failed') except Exception, e: self.assertTrue("Script 'unknown.sql' was not found" in str(e))
def test_run_script_syntax_error(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando_error.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) try: sqlplus.run_script(script) self.fail('Should have failed') except Exception, e: self.assertTrue("ERROR" in e.message)
def test_run_script_syntax_error(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando_error.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) try: sqlplus.run_script(script) self.fail('Should have failed') except Exception, e: self.assertTrue("ERROR" in e.message)
def test_cast_query(self): driver = SqlplusCommando(configuration=self.CONFIG) driver.run_script(os.path.join(self.SQL_DIR, 'test_sqlplus_commando_cast_query.sql')) expected = ( {'I': 123, 'F': 1.23, 'D': datetime.datetime(2014, 3, 29, 11, 18, 0), 'S': 'test'}, {'I': -456, 'F': -1.2e-34, 'D': datetime.datetime(2014, 3, 29), 'S': 123}, ) actual = driver.run_query("SELECT i, f, d, s FROM test;", cast=True) self.assertEqual(expected, actual) driver.run_script(os.path.join(self.SQL_DIR, 'test_sqlplus_commando_cast_query.sql')) expected = ( {'I': '123', 'F': '1,23', 'D': '29/03/14 11:18:00,000000', 'S': 'test'}, {'I': '-456', 'F': '-1,200E-34', 'D': '29/03/14 00:00:00,000000', 'S': '123'}, ) actual = driver.run_query("SELECT i, f, d, s FROM test;", cast=False) self.assertEqual(expected, actual)
def test_cast_query(self): driver = SqlplusCommando(configuration=self.CONFIG) driver.run_script( os.path.join(self.SQL_DIR, 'test_sqlplus_commando_cast_query.sql')) expected = ( { 'I': 123, 'F': 1.23, 'D': datetime.datetime(2014, 3, 29, 11, 18, 0), 'S': 'test' }, { 'I': -456, 'F': -1.2e-34, 'D': datetime.datetime(2014, 3, 29), 'S': 123 }, ) actual = driver.run_query("SELECT i, f, d, s FROM test;", cast=True) self.assertEqual(expected, actual) driver.run_script( os.path.join(self.SQL_DIR, 'test_sqlplus_commando_cast_query.sql')) expected = ( { 'I': '123', 'F': '1,23', 'D': '29/03/14 11:18:00,000000', 'S': 'test' }, { 'I': '-456', 'F': '-1,200E-34', 'D': '29/03/14 00:00:00,000000', 'S': '123' }, ) actual = driver.run_query("SELECT i, f, d, s FROM test;", cast=False) self.assertEqual(expected, actual)
def test_run_script_nominal(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) expected = ({'ID': 1, 'NAME': 'Réglisse', 'AGE': 14}, ) actual = sqlplus.run_script(script) self.assertEqual(expected, actual)
def test_run_script_nominal(self): script = os.path.join(self.SQL_DIR, 'test_sqlplus_commando.sql') sqlplus = SqlplusCommando(configuration=self.CONFIG) expected = ({'ID': 1, 'NAME': 'Réglisse', 'AGE': 14},) actual = sqlplus.run_script(script) self.assertEqual(expected, actual)