from unittest import TestCase

from turbodbc import connect, InterfaceError, DatabaseError


dsn = "Exasol R&D test database"


class TestConnection(TestCase):
    def test_closed_connection_raises_when_used(self):
        connection = connect(dsn)

        connection.close()

        with self.assertRaises(InterfaceError):
            connection.cursor()

        with self.assertRaises(InterfaceError):
            connection.commit()

    def test_closing_twice_is_ok(self):
        connection = connect(dsn)
 
        connection.close()
        connection.close()

    def test_closing_connection_closes_all_cursors(self):
        connection = connect(dsn)
        cursor_1 = connection.cursor()
        cursor_2 = connection.cursor()
        connection.close()

        with self.assertRaises(InterfaceError):
            cursor_1.execute("SELECT 42")

        with self.assertRaises(InterfaceError):
            cursor_2.execute("SELECT 42")

    def test_no_autocommit(self):
        connection = connect(dsn)

        connection.cursor().execute('CREATE TABLE test_no_autocommit (a INTEGER)')
        connection.close()

        connection = connect(dsn)
        with self.assertRaises(DatabaseError):
            connection.cursor().execute('SELECT * FROM test_no_autocommit')

@@ -1281,8 +1281,486 @@
 ommit')%0A
+%0A    def test_commit(self):%0A        connection = connect(dsn)%0A%0A        connection.cursor().execute('CREATE TABLE test_commit (a INTEGER)')%0A        connection.commit()%0A%0A        connection.close()%0A%0A        connection = connect(dsn)%0A        cursor = connection.cursor()%0A        cursor.execute('SELECT * FROM test_commit')%0A        results = cursor.fetchall()%0A        self.assertEqual(results, %5B%5D)%0A        %0A        cursor.execute('DROP TABLE test_commit')%0A        connection.commit()

Add test for commit