2023-03-29 02:46:12 +05:30
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from datahub.ingestion.api.common import PipelineContext
|
|
|
|
from datahub.ingestion.source.sql.postgres import PostgresConfig, PostgresSource
|
2021-07-20 19:31:42 +05:30
|
|
|
|
|
|
|
|
|
|
|
def _base_config():
|
|
|
|
return {"username": "user", "password": "password", "host_port": "host:1521"}
|
|
|
|
|
|
|
|
|
|
|
|
def test_database_alias_takes_precendence():
|
|
|
|
config = PostgresConfig.parse_obj(
|
|
|
|
{
|
|
|
|
**_base_config(),
|
|
|
|
"database_alias": "ops_database",
|
|
|
|
"database": "postgres",
|
|
|
|
}
|
|
|
|
)
|
2023-03-29 02:46:12 +05:30
|
|
|
mock_inspector = mock.MagicMock()
|
|
|
|
assert (
|
|
|
|
PostgresSource(config, PipelineContext(run_id="test")).get_identifier(
|
|
|
|
schema="superset", entity="logs", inspector=mock_inspector
|
|
|
|
)
|
|
|
|
== "ops_database.superset.logs"
|
|
|
|
)
|
2021-07-20 19:31:42 +05:30
|
|
|
|
|
|
|
|
|
|
|
def test_database_in_identifier():
|
|
|
|
config = PostgresConfig.parse_obj({**_base_config(), "database": "postgres"})
|
2023-03-29 02:46:12 +05:30
|
|
|
mock_inspector = mock.MagicMock()
|
|
|
|
assert (
|
|
|
|
PostgresSource(config, PipelineContext(run_id="test")).get_identifier(
|
|
|
|
schema="superset", entity="logs", inspector=mock_inspector
|
|
|
|
)
|
|
|
|
== "postgres.superset.logs"
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
def test_current_sqlalchemy_database_in_identifier():
|
|
|
|
config = PostgresConfig.parse_obj({**_base_config()})
|
|
|
|
mock_inspector = mock.MagicMock()
|
|
|
|
mock_inspector.engine.url.database = "current_db"
|
|
|
|
assert (
|
|
|
|
PostgresSource(config, PipelineContext(run_id="test")).get_identifier(
|
|
|
|
schema="superset", entity="logs", inspector=mock_inspector
|
|
|
|
)
|
|
|
|
== "current_db.superset.logs"
|
|
|
|
)
|