From 501f56af5cbc2d7e98a3c60d59f8d658c3deab85 Mon Sep 17 00:00:00 2001 From: Leo Schick Date: Fri, 27 Jan 2023 10:59:48 +0100 Subject: [PATCH] fix & simplify tests --- tests/db_test_helper.py | 15 +++++++++++++++ tests/mssql/test_mssql.py | 15 ++------------- tests/postgres/test_postgres.py | 15 ++------------- tests/test_databricks.py | 15 ++------------- 4 files changed, 21 insertions(+), 39 deletions(-) diff --git a/tests/db_test_helper.py b/tests/db_test_helper.py index d0e551f..ba3b3dc 100644 --- a/tests/db_test_helper.py +++ b/tests/db_test_helper.py @@ -40,3 +40,18 @@ def _test_sqlalchemy(db): # the SELECT of a scalar value without a table is # appropriately formatted for the backend assert conn.scalar(select(1)) == 1 + +def _test_connect(db): + connection = db.connect() + cursor = connection.cursor() + try: + cursor.execute('SELECT 1') + row = cursor.fetchone() + assert row[0] == 1 + connection.commit() + except Exception as e: + connection.rollback() + raise e + finally: + cursor.close() + connection.close() diff --git a/tests/mssql/test_mssql.py b/tests/mssql/test_mssql.py index 9459978..42e1f26 100644 --- a/tests/mssql/test_mssql.py +++ b/tests/mssql/test_mssql.py @@ -60,19 +60,8 @@ def test_mssql_connect(mssql_db): """ A simple test to check if the connect API works. """ - connection = MSSQL_DB.connect() - cursor = connection.cursor() - try: - cursor.execute('SELECT 1') - row = cursor.fetchone() - assert row[0] == 1 - connection.commit() - except Exception as e: - connection.rollback() - raise e - finally: - cursor.close() - connection.close() + from ..db_test_helper import _test_connect + _test_connect(mssql_db) diff --git a/tests/postgres/test_postgres.py b/tests/postgres/test_postgres.py index 76c3257..3f4c6b6 100644 --- a/tests/postgres/test_postgres.py +++ b/tests/postgres/test_postgres.py @@ -156,16 +156,5 @@ def test_postgres_connect(postgres_db): """ A simple test to check if the connect API works. """ - connection = POSTGRES_DB.connect() - cursor = connection.cursor() - try: - cursor.execute('SELECT 1') - row = cursor.fetchone() - assert row[0] == 1 - connection.commit() - except Exception as e: - connection.rollback() - raise e - finally: - cursor.close() - connection.close() + from ..db_test_helper import _test_connect + _test_connect(postgres_db) diff --git a/tests/test_databricks.py b/tests/test_databricks.py index 220f440..145c098 100644 --- a/tests/test_databricks.py +++ b/tests/test_databricks.py @@ -47,16 +47,5 @@ def test_databricks_connect(): """ A simple test to check if the connect API works. """ - connection = DATABRICKS_DB.connect() - cursor = connection.cursor() - try: - cursor.execute('SELECT 1') - row = cursor.fetchone() - assert row[0] == 1 - connection.commit() - except Exception as e: - connection.rollback() - raise e - finally: - cursor.close() - connection.close() + from .db_test_helper import _test_connect + _test_connect(DATABRICKS_DB)