Skip to content

Commit

Permalink
test: Use future=True param to create engines (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Dec 8, 2023
1 parent 9df942d commit 40ff4cf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
28 changes: 14 additions & 14 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

def setup_test_table(table_name, sqlalchemy_url):
"""setup any state specific to the execution of the given module."""
engine = sqlalchemy.create_engine(sqlalchemy_url)
engine = sqlalchemy.create_engine(sqlalchemy_url, future=True)
fake = Faker()

date1 = datetime.date(2022, 11, 1)
Expand All @@ -49,7 +49,7 @@ def setup_test_table(table_name, sqlalchemy_url):
Column("updated_at", DateTime(), nullable=False),
Column("name", String()),
)
with engine.connect() as conn:
with engine.begin() as conn:
metadata_obj.create_all(conn)
conn.execute(text(f"TRUNCATE TABLE {table_name}"))
for _ in range(1000):
Expand All @@ -60,8 +60,8 @@ def setup_test_table(table_name, sqlalchemy_url):


def teardown_test_table(table_name, sqlalchemy_url):
engine = sqlalchemy.create_engine(sqlalchemy_url)
with engine.connect() as conn:
engine = sqlalchemy.create_engine(sqlalchemy_url, future=True)
with engine.begin() as conn:
conn.execute(text(f"DROP TABLE {table_name}"))


Expand Down Expand Up @@ -137,7 +137,7 @@ def test_temporal_datatypes():
schema checks, and performs similar tests on times and timestamps.
"""
table_name = "test_temporal_datatypes"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
Expand All @@ -147,7 +147,7 @@ def test_temporal_datatypes():
Column("column_time", TIME),
Column("column_timestamp", TIMESTAMP),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down Expand Up @@ -197,7 +197,7 @@ def test_temporal_datatypes():
def test_jsonb_json():
"""JSONB and JSON Objects weren't being selected, make sure they are now"""
table_name = "test_jsonb_json"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
Expand All @@ -206,7 +206,7 @@ def test_jsonb_json():
Column("column_jsonb", JSONB),
Column("column_json", JSON),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down Expand Up @@ -248,15 +248,15 @@ def test_jsonb_json():
def test_decimal():
"""Schema was wrong for Decimal objects. Check they are correctly selected."""
table_name = "test_decimal"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
table_name,
metadata_obj,
Column("column", Numeric()),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down Expand Up @@ -294,12 +294,12 @@ def test_decimal():
def test_filter_schemas():
"""Only return tables from a given schema"""
table_name = "test_filter_schemas"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(table_name, metadata_obj, Column("id", BIGINT), schema="new_schema")

with engine.connect() as conn:
with engine.begin() as conn:
conn.execute(text("CREATE SCHEMA IF NOT EXISTS new_schema"))
if table.exists(conn):
table.drop(conn)
Expand Down Expand Up @@ -333,7 +333,7 @@ def test_invalid_python_dates():
"""
table_name = "test_invalid_python_dates"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
Expand All @@ -342,7 +342,7 @@ def test_invalid_python_dates():
Column("date", DATE),
Column("datetime", DateTime),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down
9 changes: 5 additions & 4 deletions tests/test_replication_key.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Tests standard tap features using the built-in SDK tests library."""

import copy
import json

Expand Down Expand Up @@ -54,7 +55,7 @@ def test_null_replication_key_with_start_date():
greater than the start date should be synced.
"""
table_name = "test_null_replication_key_with_start_date"
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"])
engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
Expand All @@ -63,7 +64,7 @@ def test_null_replication_key_with_start_date():
Column("data", String()),
Column("updated_at", TIMESTAMP),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down Expand Up @@ -111,7 +112,7 @@ def test_null_replication_key_without_start_date():

modified_config = copy.deepcopy(SAMPLE_CONFIG)
modified_config["start_date"] = None
engine = sqlalchemy.create_engine(modified_config["sqlalchemy_url"])
engine = sqlalchemy.create_engine(modified_config["sqlalchemy_url"], future=True)

metadata_obj = MetaData()
table = Table(
Expand All @@ -120,7 +121,7 @@ def test_null_replication_key_without_start_date():
Column("data", String()),
Column("updated_at", TIMESTAMP),
)
with engine.connect() as conn:
with engine.begin() as conn:
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down

0 comments on commit 40ff4cf

Please sign in to comment.