Skip to content

Commit

Permalink
Merge branch 'main' into object-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Dec 8, 2023
2 parents 57dc360 + 678737e commit d5c1db9
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 22 deletions.
2 changes: 1 addition & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ faker = ">=18.5.1,<21.0.0"
flake8 = "^6.0.0"
isort = "^5.10.1"
mypy = "1.7.1"
pendulum = "~=2.1"
pre-commit = "^3.0.4"
pydocstyle = "^6.1.1"
singer-sdk = {version = "*", extras = ["testing"]}
Expand Down
34 changes: 17 additions & 17 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from faker import Faker
from singer_sdk.testing import get_tap_test_class, suites
from singer_sdk.testing.runners import TapTestRunner
from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, String, Table
from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, String, Table, text
from sqlalchemy.dialects.postgresql import BIGINT, DATE, JSON, JSONB, TIME, TIMESTAMP
from test_replication_key import TABLE_NAME, TapTestReplicationKey
from test_selected_columns_only import (
Expand All @@ -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,9 +49,9 @@ 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(f"TRUNCATE TABLE {table_name}")
conn.execute(text(f"TRUNCATE TABLE {table_name}"))
for _ in range(1000):
insert = test_replication_key_table.insert().values(
updated_at=fake.date_between(date1, date2), name=fake.name()
Expand All @@ -60,9 +60,9 @@ 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:
conn.execute(f"DROP TABLE {table_name}")
engine = sqlalchemy.create_engine(sqlalchemy_url, future=True)
with engine.begin() as conn:
conn.execute(text(f"DROP TABLE {table_name}"))


custom_test_replication_key = suites.TestSuite(
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 Down Expand Up @@ -273,15 +273,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 @@ -319,13 +319,13 @@ 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:
conn.execute("CREATE SCHEMA IF NOT EXISTS new_schema")
with engine.begin() as conn:
conn.execute(text("CREATE SCHEMA IF NOT EXISTS new_schema"))
if table.exists(conn):
table.drop(conn)
metadata_obj.create_all(conn)
Expand Down Expand Up @@ -358,7 +358,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 @@ -367,7 +367,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 d5c1db9

Please sign in to comment.