2023-03-17 07:58:14 -07:00
|
|
|
import sys
|
2023-03-18 12:59:43 -07:00
|
|
|
from typing import Any, Dict, List, Optional, Union
|
2023-03-17 07:58:14 -07:00
|
|
|
|
|
|
|
import pydantic
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
sys.path.append(".")
|
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
from enum import Enum
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
from docs_config_table import FieldRow
|
|
|
|
|
|
|
|
from datahub.configuration.common import ConfigModel
|
|
|
|
|
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
class Platform(Enum):
|
2025-06-30 20:16:56 +05:30
|
|
|
DBT = "DBT"
|
|
|
|
LOOKER = "LOOKER"
|
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
|
|
|
|
class Connection(ConfigModel):
|
|
|
|
path: Union[pydantic.FilePath, pydantic.DirectoryPath]
|
|
|
|
headers: Dict[str, str]
|
2023-03-18 12:59:43 -07:00
|
|
|
connect_args: Optional[Dict[str, Any]] = pydantic.Field(
|
|
|
|
default=None,
|
|
|
|
description="Connect args to pass to underlying driver",
|
|
|
|
exclude=True,
|
|
|
|
)
|
2023-03-17 07:58:14 -07:00
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
class BaseConfig(ConfigModel):
|
2025-06-30 20:16:56 +05:30
|
|
|
"""
|
2023-03-17 07:58:14 -07:00
|
|
|
A base config class
|
2025-06-30 20:16:56 +05:30
|
|
|
"""
|
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
env: str
|
|
|
|
platform: Optional[Platform] = Platform.DBT
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
|
2023-03-17 07:58:14 -07:00
|
|
|
class FinalConfig(BaseConfig):
|
|
|
|
connection: Connection
|
|
|
|
field_array: List[str]
|
|
|
|
connection_map: Dict[str, Connection]
|
|
|
|
|
|
|
|
|
|
|
|
def test_field_row():
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=map].[type=Connection].connection_map.[type=union].[type=string(file-path)].path"
|
2023-03-17 07:58:14 -07:00
|
|
|
assert FieldRow.field_path_to_components(field_path) == [
|
2025-06-30 20:16:56 +05:30
|
|
|
"connection_map",
|
|
|
|
"`key`",
|
|
|
|
"path",
|
2023-03-17 07:58:14 -07:00
|
|
|
]
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=map].[type=Connection].connection_map.[type=map].[type=string].headers"
|
2023-03-17 07:58:14 -07:00
|
|
|
assert FieldRow.field_path_to_components(field_path) == [
|
2025-06-30 20:16:56 +05:30
|
|
|
"connection_map",
|
|
|
|
"`key`",
|
|
|
|
"headers",
|
2023-03-17 07:58:14 -07:00
|
|
|
]
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=Connection].connection.[type=map].[type=string].headers"
|
|
|
|
assert FieldRow.field_path_to_components(field_path) == ["connection", "headers"]
|
2023-03-17 07:58:14 -07:00
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=map].[type=Connection].connection_map.[type=union].[type=string(file-path)].path"
|
2023-03-17 07:58:14 -07:00
|
|
|
assert FieldRow.field_path_to_components(field_path) == [
|
2025-06-30 20:16:56 +05:30
|
|
|
"connection_map",
|
|
|
|
"`key`",
|
|
|
|
"path",
|
2023-03-17 07:58:14 -07:00
|
|
|
]
|
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=string].env"
|
|
|
|
assert FieldRow.field_path_to_components(field_path) == ["env"]
|
2023-03-17 07:58:14 -07:00
|
|
|
|
2025-06-30 20:16:56 +05:30
|
|
|
field_path = "[version=2.0].[type=FinalConfig].[type=map].[type=Connection].connection_map.[type=union].[type=string(file-path)].path"
|
2023-03-17 07:58:14 -07:00
|
|
|
assert FieldRow.field_path_to_components(field_path) == [
|
2025-06-30 20:16:56 +05:30
|
|
|
"connection_map",
|
|
|
|
"`key`",
|
|
|
|
"path",
|
2023-03-17 07:58:14 -07:00
|
|
|
]
|