Skip to content

Commit

Permalink
DRY
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 30, 2024
1 parent 3dacb7d commit 6ae3858
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions tests/samples/test_target_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@
from singer_sdk.target_base import SQLTarget


def get_table(config: dict, table_name: str) -> sa.Table:
"""Get SQLAlchemy metadata and table for inspection.
Args:
config: Target configuration dictionary containing database path
table_name: Name of the table to inspect
Returns:
Tuple of (metadata, table)
"""
db_path = config["path_to_db"]
engine = sa.create_engine(f"sqlite:///{db_path}")
meta = sa.MetaData()
meta.reflect(bind=engine)
return meta.tables[table_name]


@pytest.fixture
def path_to_target_db(tmp_path: Path) -> Path:
return Path(f"{tmp_path}/target_test.db")
Expand Down Expand Up @@ -289,11 +306,7 @@ def test_sqlite_activate_version(
)

# Check that the record metadata was added
db_path = sqlite_sample_target_hard_delete.config["path_to_db"]
engine = sa.create_engine(f"sqlite:///{db_path}")
meta = sa.MetaData()
meta.reflect(bind=engine)
table = meta.tables[test_tbl]
table = get_table(sqlite_sample_target_hard_delete.config, test_tbl)

assert "_sdc_table_version" in table.columns
assert type(table.columns["_sdc_table_version"].type) is sa.INTEGER
Expand Down Expand Up @@ -340,11 +353,7 @@ def test_sqlite_no_activate_version(
)

# Check that the record metadata was added
db_path = sqlite_sample_target_no_activate_version.config["path_to_db"]
engine = sa.create_engine(f"sqlite:///{db_path}")
meta = sa.MetaData()
meta.reflect(bind=engine)
table = meta.tables[test_tbl]
table = get_table(sqlite_sample_target_no_activate_version.config, test_tbl)

assert "col_a" in table.columns
assert "_sdc_table_version" not in table.columns
Expand Down Expand Up @@ -387,11 +396,7 @@ def test_sqlite_add_record_metadata(sqlite_target_add_record_metadata: SQLTarget
)

# Check that the record metadata was added
db_path = sqlite_target_add_record_metadata.config["path_to_db"]
engine = sa.create_engine(f"sqlite:///{db_path}")
meta = sa.MetaData()
meta.reflect(bind=engine)
table = meta.tables[test_tbl]
table = get_table(sqlite_target_add_record_metadata.config, test_tbl)

assert "_sdc_received_at" in table.columns
assert type(table.columns["_sdc_received_at"].type) is sa.DATETIME
Expand Down

0 comments on commit 6ae3858

Please sign in to comment.