def test_execute_commit_false(self): with TRN: sql = """INSERT INTO qiita.test_table (str_column, int_column) VALUES (%s, %s) RETURNING str_column, int_column""" args = [['insert1', 1], ['insert2', 2], ['insert3', 3]] TRN.add(sql, args, many=True) obs = TRN.execute() exp = [[['insert1', 1]], [['insert2', 2]], [['insert3', 3]]] self.assertEqual(obs, exp) self._assert_sql_equal([]) TRN.commit() self._assert_sql_equal([('insert1', True, 1), ('insert2', True, 2), ('insert3', True, 3)])
def test_context_manager_checker(self): with self.assertRaises(RuntimeError): TRN.add("SELECT 42") with self.assertRaises(RuntimeError): TRN.execute() with self.assertRaises(RuntimeError): TRN.commit() with self.assertRaises(RuntimeError): TRN.rollback() with TRN: TRN.add("SELECT 42") with self.assertRaises(RuntimeError): TRN.execute()