Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_no_autocommit(dsn, configuration):
connection = connect(dsn, **get_credentials(configuration))
connection.cursor().execute('CREATE TABLE test_no_autocommit (a INTEGER)')
connection.close()
connection = connect(dsn, **get_credentials(configuration))
with pytest.raises(DatabaseError):
connection.cursor().execute('SELECT * FROM test_no_autocommit')
def test_rollback(dsn, configuration):
connection = connect(dsn, **get_credentials(configuration))
connection.cursor().execute('CREATE TABLE test_rollback (a INTEGER)')
connection.rollback()
with pytest.raises(DatabaseError):
connection.cursor().execute('SELECT * FROM test_rollback')
def test_insert_duplicate_uniquecol_raises(dsn, configuration):
with open_cursor(configuration) as cursor:
with query_fixture(cursor, configuration, 'INSERT DUPLICATE UNIQUECOL') as table_name:
with pytest.raises(DatabaseError) as ex:
cursor.execute("INSERT INTO {table_name} VALUES (1)".format(table_name=table_name))
# some databases (e.g. exasol) report failure not in the execute statement above, but only
# when closing the odbc handle, i.e. at cursor.close:
cursor.close()
def test_connect_raises_on_invalid_additional_option(dsn, configuration):
additional_option = {configuration['capabilities']['connection_user_option']: 'invalid user'}
with pytest.raises(DatabaseError):
connect(dsn=dsn, **additional_option)
def test_connect_raises_on_invalid_dsn():
invalid_dsn = 'This data source does not exist'
with pytest.raises(DatabaseError):
connect(invalid_dsn)