-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add regression test nox target * Add regression test for invalid auto commit behavior (Issue-335) * Add regression tests to integration test target * Fix invalid auto commit behavior * Update change-log * Move odbc helpers to exasol driver(s) package Co-authored-by: Sebastian Bär <redcatbear@ursus-minor.de>
- Loading branch information
1 parent
09ac067
commit f3d6c28
Showing
6 changed files
with
108 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import pytest | ||
from sqlalchemy import ( | ||
Column, | ||
Integer, | ||
MetaData, | ||
String, | ||
Table, | ||
create_engine, | ||
insert, | ||
) | ||
|
||
from exasol.driver.odbc import ( | ||
ODBC_DRIVER, | ||
odbcconfig, | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def pyodbc_connection_string(exasol_config): | ||
config = exasol_config | ||
return ( | ||
f"exa+pyodbc://{config.username}:{config.password}@{config.host}:{config.port}/" | ||
f"?DEFAULTPARAMSIZE=200&INTTYPESINRESULTSIFPOSSIBLE=y" | ||
"&FINGERPRINT=NOCERTCHECK&CONNECTIONLCALL=en_US.UTF-8&driver=EXAODBC" | ||
) | ||
|
||
|
||
@pytest.fixture() | ||
def test_schema(control_connection): | ||
connection = control_connection | ||
schema = "REGRESSION_335" | ||
connection.execute(f"CREATE SCHEMA {schema}") | ||
connection.commit() | ||
yield schema | ||
connection.execute(f"DROP SCHEMA IF EXISTS {schema} CASCADE") | ||
connection.commit() | ||
|
||
|
||
@pytest.fixture() | ||
def users_table(control_connection, test_schema): | ||
connection = control_connection | ||
table_name = "users" | ||
connection.execute( | ||
f"create table {test_schema}.{table_name} (id DECIMAL(18) identity primary key, name VARCHAR(2000) UTF8)" | ||
) | ||
connection.commit() | ||
yield test_schema, table_name | ||
|
||
|
||
def test_lastrowid_does_not_create_extra_commit( | ||
exasol_config, users_table, pyodbc_connection_string | ||
): | ||
""" | ||
For further details on this regression see `Issue-335 <https://github.com/exasol/sqlalchemy-exasol/issues/335>`_. | ||
""" | ||
schema_name, table_name = users_table | ||
metadata = MetaData() | ||
engine = create_engine(pyodbc_connection_string) | ||
|
||
table = Table( | ||
table_name, | ||
metadata, | ||
Column("id", Integer, primary_key=True), | ||
Column("name", String(2000)), | ||
schema=schema_name, | ||
) | ||
|
||
with odbcconfig(ODBC_DRIVER): | ||
conn = engine.connect() | ||
trans = conn.begin() | ||
|
||
# Insert without an explicit ID will trigger a call to `get_lastrowid` | ||
# which in turn cause the unintended autocommit | ||
insert_statement = insert(table).values(name="Gandalf") | ||
conn.execute(insert_statement) | ||
trans.rollback() | ||
|
||
result = conn.execute(f"SELECT * FROM {schema_name}.{table_name};").fetchall() | ||
conn.close() | ||
|
||
assert len(result) == 0 |