Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Slightly refactor fixed config values into tests/settings.py #312

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.vscode/**
# Secrets and internal config files
**/.secrets/*
Expand Down
Empty file added tests/__init__.py
Empty file.
5 changes: 5 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# PostgreSQL default schema name.
DB_SCHEMA_NAME = "public"

# SQLAlchemy connection URL.
DB_SQLALCHEMY_URL = "postgresql://postgres:postgres@localhost:5432/postgres"
17 changes: 9 additions & 8 deletions tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
from singer_sdk.testing.runners import TapTestRunner
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 (
from tests.settings import DB_SCHEMA_NAME, DB_SQLALCHEMY_URL
from tests.test_replication_key import TABLE_NAME, TapTestReplicationKey
from tests.test_selected_columns_only import (
TABLE_NAME_SELECTED_COLUMNS_ONLY,
TapTestSelectedColumnsOnly,
)
Expand All @@ -21,7 +22,7 @@

SAMPLE_CONFIG = {
"start_date": pendulum.datetime(2022, 11, 1).to_iso8601_string(),
"sqlalchemy_url": "postgresql://postgres:postgres@localhost:5432/postgres",
"sqlalchemy_url": DB_SQLALCHEMY_URL,
}

NO_SQLALCHEMY_CONFIG = {
Expand Down Expand Up @@ -159,7 +160,7 @@ def test_temporal_datatypes():
conn.execute(insert)
tap = TapPostgres(config=SAMPLE_CONFIG)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down Expand Up @@ -217,7 +218,7 @@ def test_jsonb_json():
conn.execute(insert)
tap = TapPostgres(config=SAMPLE_CONFIG)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down Expand Up @@ -268,7 +269,7 @@ def test_decimal():
conn.execute(insert)
tap = TapPostgres(config=SAMPLE_CONFIG)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down Expand Up @@ -354,7 +355,7 @@ def test_invalid_python_dates():
tap = TapPostgres(config=SAMPLE_CONFIG)
# Alter config and then check the data comes through as a string
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand All @@ -376,7 +377,7 @@ def test_invalid_python_dates():
copied_config["dates_as_string"] = True
tap = TapPostgres(config=copied_config)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down
7 changes: 4 additions & 3 deletions tests/test_replication_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
from singer_sdk.testing.templates import TapTestTemplate
from sqlalchemy import Column, MetaData, String, Table
from sqlalchemy.dialects.postgresql import TIMESTAMP
from tests.settings import DB_SCHEMA_NAME, DB_SQLALCHEMY_URL

from tap_postgres.tap import TapPostgres

TABLE_NAME = "test_replication_key"
SAMPLE_CONFIG = {
"start_date": pendulum.datetime(2022, 11, 1).to_iso8601_string(),
"sqlalchemy_url": "postgresql://postgres:postgres@localhost:5432/postgres",
"sqlalchemy_url": DB_SQLALCHEMY_URL,
}


Expand Down Expand Up @@ -80,7 +81,7 @@ def test_null_replication_key_with_start_date():
conn.execute(insert)
tap = TapPostgres(config=SAMPLE_CONFIG)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down Expand Up @@ -137,7 +138,7 @@ def test_null_replication_key_without_start_date():
conn.execute(insert)
tap = TapPostgres(config=modified_config)
tap_catalog = json.loads(tap.catalog_json_text)
altered_table_name = f"public-{table_name}"
altered_table_name = f"{DB_SCHEMA_NAME}-{table_name}"
for stream in tap_catalog["streams"]:
if stream.get("stream") and altered_table_name not in stream["stream"]:
for metadata in stream["metadata"]:
Expand Down
3 changes: 2 additions & 1 deletion tests/test_selected_columns_only.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import json

from singer_sdk.testing.templates import TapTestTemplate
from tests.settings import DB_SQLALCHEMY_URL

from tap_postgres.tap import TapPostgres

TABLE_NAME_SELECTED_COLUMNS_ONLY = "test_selected_columns_only"
SAMPLE_CONFIG = {
"sqlalchemy_url": "postgresql://postgres:postgres@localhost:5432/postgres",
"sqlalchemy_url": DB_SQLALCHEMY_URL,
}


Expand Down
Loading