|
| 1 | +import copy |
1 | 2 | import datetime
|
2 | 3 | import decimal
|
3 | 4 | import json
|
|
9 | 10 | from singer_sdk.testing import get_tap_test_class, suites
|
10 | 11 | from singer_sdk.testing.runners import TapTestRunner
|
11 | 12 | from sqlalchemy import Column, DateTime, Integer, MetaData, Numeric, String, Table
|
12 |
| -from sqlalchemy.dialects.postgresql import DATE, JSONB, TIME, TIMESTAMP, JSON |
| 13 | +from sqlalchemy.dialects.postgresql import BIGINT, DATE, JSON, JSONB, TIME, TIMESTAMP |
13 | 14 | from test_replication_key import TABLE_NAME, TapTestReplicationKey
|
14 | 15 | from test_selected_columns_only import (
|
15 | 16 | TABLE_NAME_SELECTED_COLUMNS_ONLY,
|
@@ -290,6 +291,29 @@ def test_decimal():
|
290 | 291 | assert "number" in schema_message["schema"]["properties"]["column"]["type"]
|
291 | 292 |
|
292 | 293 |
|
| 294 | +def test_filter_schemas(): |
| 295 | + """Only return tables from a given schema""" |
| 296 | + table_name = "test_filter_schemas" |
| 297 | + engine = sqlalchemy.create_engine(SAMPLE_CONFIG["sqlalchemy_url"]) |
| 298 | + |
| 299 | + metadata_obj = MetaData() |
| 300 | + table = Table(table_name, metadata_obj, Column("id", BIGINT), schema="new_schema") |
| 301 | + |
| 302 | + with engine.connect() as conn: |
| 303 | + conn.execute("CREATE SCHEMA IF NOT EXISTS new_schema") |
| 304 | + if table.exists(conn): |
| 305 | + table.drop(conn) |
| 306 | + metadata_obj.create_all(conn) |
| 307 | + filter_schemas_config = copy.deepcopy(SAMPLE_CONFIG) |
| 308 | + filter_schemas_config.update({"filter_schemas": ["new_schema"]}) |
| 309 | + tap = TapPostgres(config=filter_schemas_config) |
| 310 | + tap_catalog = json.loads(tap.catalog_json_text) |
| 311 | + altered_table_name = f"new_schema-{table_name}" |
| 312 | + # Check that the only stream in the catalog is the one table put into new_schema |
| 313 | + assert len(tap_catalog["streams"]) == 1 |
| 314 | + assert tap_catalog["streams"][0]["stream"] == altered_table_name |
| 315 | + |
| 316 | + |
293 | 317 | class PostgresTestRunner(TapTestRunner):
|
294 | 318 | def run_sync_dry_run(self) -> bool:
|
295 | 319 | """
|
|
0 commit comments