98 lines
3.0 KiB
Python
98 lines
3.0 KiB
Python
import pytest
|
|
|
|
from tht.adapters.dwh import PostgresDwhAdapter, ThothRestDwhAdapter
|
|
from tht.adapters.factory import build_dwh, build_vector_store
|
|
from tht.adapters.vector import QdrantVectorStore
|
|
from tht.config import Config, ConfigError
|
|
|
|
|
|
def _config(*, dwh_type="thoth_rest", include_vectors=True):
|
|
dwh = (
|
|
{
|
|
"type": "thoth_rest",
|
|
"database": {"database": "analytics", "schema": "mart"},
|
|
"endpoint": {"base_url": "https://dwh.test/", "api_key": "reader"},
|
|
}
|
|
if dwh_type == "thoth_rest"
|
|
else {
|
|
"type": "postgres_direct",
|
|
"connection": {
|
|
"host": "db",
|
|
"database": "analytics",
|
|
"schema": "mart",
|
|
"user": "reader",
|
|
"password": "secret",
|
|
},
|
|
}
|
|
)
|
|
vectors = (
|
|
{
|
|
"type": "qdrant",
|
|
"base_url": "http://qdrant:6333",
|
|
"collection": "psd-clinical",
|
|
}
|
|
if include_vectors
|
|
else None
|
|
)
|
|
legacy_database = (
|
|
dwh["connection"]
|
|
if dwh_type == "postgres_direct"
|
|
else {
|
|
**dwh["database"],
|
|
"user": "rest",
|
|
"password": "",
|
|
"transport": "rest",
|
|
}
|
|
)
|
|
payload = {"dwh": dwh, "database": legacy_database}
|
|
if vectors is not None:
|
|
payload["vectors"] = vectors
|
|
payload["embeddings"] = {
|
|
"provider": "ollama_internal",
|
|
"base_url": "http://embedding:11434",
|
|
"model": "qwen3-embedding:0.6b",
|
|
"dim": 1024,
|
|
}
|
|
config = Config.model_validate(payload)
|
|
config._workspace_id = "psd-clinical"
|
|
config._workspace_revision = "a" * 40
|
|
return config
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
("dwh_type", "adapter_type"),
|
|
[("postgres_direct", PostgresDwhAdapter), ("thoth_rest", ThothRestDwhAdapter)],
|
|
)
|
|
def test_factory_selects_dwh_adapter(dwh_type, adapter_type):
|
|
assert isinstance(build_dwh(_config(dwh_type=dwh_type)), adapter_type)
|
|
|
|
|
|
def test_factory_rejects_require_existing_without_embedding_dimension():
|
|
config = _config()
|
|
config.vectors.collection_lifecycle = "require_existing"
|
|
config.embeddings = None
|
|
|
|
with pytest.raises(ConfigError, match="explicit positive embedding dimension"):
|
|
build_vector_store(config)
|
|
|
|
|
|
def test_factory_selects_qdrant_for_schema_v3_runtime():
|
|
config = _config(dwh_type="postgres_direct")
|
|
|
|
store = build_vector_store(config, require_write=True)
|
|
|
|
assert isinstance(store, QdrantVectorStore)
|
|
assert store.capabilities.search is True
|
|
assert store.capabilities.upsert is True
|
|
|
|
|
|
def test_factory_requires_qdrant_vector_resource():
|
|
with pytest.raises(ConfigError, match="vectors"):
|
|
build_vector_store(_config(include_vectors=False))
|
|
|
|
|
|
def test_factory_propagates_non_default_statement_timeout():
|
|
config = _config(dwh_type="postgres_direct")
|
|
config.execution.statement_timeout_ms = 12_345
|
|
assert build_dwh(config)._statement_timeout_ms == 12_345
|