Example #1
0
def test_make_postgres_table_name(
    handler_type: str, schema: str, table: str, user_prefix: str, expected_name: str
):
    name = ds.make_postgres_table_name(
        handler_type=handler_type, schema=schema, table=table, user_prefix=user_prefix
    )
    assert len(name) <= ds.MAX_POSTGRES_NAME_LIMIT
    assert name == expected_name[: ds.MAX_POSTGRES_NAME_LIMIT]
def test_to_immuta_objects(
    db_keys: Dict[str, str],
    handler_type: str,
    expected_type: Any,
    columns: List[ds.DataSourceColumn],
    query_engine_target_schema: str,
    prefix_query_engine_names_with_schema: bool,
    prefix_query_engine_names_with_handler: bool,
):
    base_config = {
        "username": "******",
        "password": "******",
        "database": "baz",
        "owner_profile_id": 0,
    }
    config = {**base_config, **db_keys}
    config["handler_type"] = handler_type
    source, handler, schema_evolution = ds.to_immuta_objects(
        table="foo",
        schema="bar",
        config=config,
        columns=columns,
        bodata_schema_name=query_engine_target_schema,
        prefix_query_engine_names_with_schema=
        prefix_query_engine_names_with_schema,
        prefix_query_engine_names_with_handler=
        prefix_query_engine_names_with_handler,
    )
    assert source.name == ds.make_immuta_datasource_name(
        table="foo",
        schema="bar",
        handler_type=handler_type,
        user_prefix="",
    )
    assert source.sqlTableName == ds.make_postgres_table_name(
        table="foo",
        schema="bar" if prefix_query_engine_names_with_schema else "",
        handler_type=handler_type
        if prefix_query_engine_names_with_handler else "",
        user_prefix="",
    )
    assert source.blobHandlerType == handler_type
    assert handler.metadata.bodataSchemaName == query_engine_target_schema
    assert isinstance(handler, ds.Handler)
    assert isinstance(handler.metadata, expected_type)
    assert isinstance(schema_evolution, ds.SchemaEvolutionMetadata)
Example #3
0
def test_to_immuta_objects(
    db_keys: Dict[str, str],
    handler_type: str,
    expected_type: Any,
    columns: List[ds.DataSourceColumn],
):
    base_config = {"username": "******", "password": "******", "database": "baz"}
    config = {**base_config, **db_keys}
    config["handler_type"] = handler_type
    source, handler = ds.to_immuta_objects(
        table="foo", schema="bar", config=config, columns=columns
    )
    assert source.name == ds.make_immuta_table_name(
        table="foo", schema="bar", handler_type=handler_type, user_prefix=""
    )
    assert source.sqlTableName == ds.make_postgres_table_name(
        table="foo", schema="bar", handler_type=handler_type, user_prefix=""
    )
    assert source.blobHandlerType == handler_type
    assert isinstance(handler, ds.Handler)
    assert isinstance(handler.metadata, expected_type)