-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathtest_sl_client.py
More file actions
97 lines (74 loc) · 3.24 KB
/
test_sl_client.py
File metadata and controls
97 lines (74 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
from typing import AsyncIterator, Iterator
import pytest
from pytest_subtests import SubTests
from dbtsl.api.shared.query_params import QueryParameters
from dbtsl.client.asyncio import AsyncSemanticLayerClient
from dbtsl.client.base import ADBC, GRAPHQL
from dbtsl.client.sync import SyncSemanticLayerClient
from ..conftest import Credentials
from ..query_test_cases import TEST_QUERIES
from ..util import maybe_await
from .conftest import BothClients
@pytest.fixture(scope="module")
async def async_client(credentials: Credentials) -> AsyncIterator[AsyncSemanticLayerClient]:
client = AsyncSemanticLayerClient(
environment_id=credentials.environment_id,
auth_token=credentials.token,
host=credentials.host,
client_partner_source="dbt-e2e-tests",
)
async with client.session():
yield client
@pytest.fixture(scope="module")
def sync_client(credentials: Credentials) -> Iterator[SyncSemanticLayerClient]:
client = SyncSemanticLayerClient(
environment_id=credentials.environment_id,
auth_token=credentials.token,
host=credentials.host,
client_partner_source="dbt-e2e-tests",
)
with client.session():
yield client
@pytest.fixture(scope="module")
async def client(
request: pytest.FixtureRequest, sync_client: SyncSemanticLayerClient, async_client: AsyncSemanticLayerClient
) -> BothClients:
if request.param == "sync":
return sync_client
return async_client
pytestmark = pytest.mark.asyncio(scope="module")
# NOTE: grouping all these tests in one because they depend on each other, i.e
# dimensions depends on metrics etc
async def test_client_metadata(subtests: SubTests, client: BothClients) -> None:
with subtests.test("metrics"):
metrics = await maybe_await(client.metrics())
assert len(metrics) > 0
metric = metrics[0]
with subtests.test("dimensions"):
dims = await maybe_await(client.dimensions(metrics=[metric.name]))
assert len(dims) > 0
assert dims == metric.dimensions
with subtests.test("entities"):
entities = await maybe_await(client.entities(metrics=[metric.name]))
assert len(entities) > 0
assert entities == metric.entities
with subtests.test("dimension_values"):
dimension = metric.dimensions[0]
dim_values = await maybe_await(client.dimension_values(metrics=[metric.name], group_by=dimension.name))
assert len(dim_values) > 0
with subtests.test("saved_queries"):
sqs = await maybe_await(client.saved_queries())
assert len(sqs) > 0
@pytest.mark.parametrize("api", [ADBC, GRAPHQL])
@pytest.mark.parametrize("query", TEST_QUERIES)
async def test_client_query(api: str, query: QueryParameters, client: BothClients) -> None:
client._method_map["query"] = api # type: ignore
# TODO: fix typing on client.query
table = await maybe_await(client.query(**query)) # type: ignore
assert len(table) > 0
@pytest.mark.parametrize("query", TEST_QUERIES)
async def test_client_compile_sql_adhoc_query(query: QueryParameters, client: BothClients) -> None:
# TODO: fix typing on client.compile_sql
sql = await maybe_await(client.compile_sql(**query)) # type: ignore
assert len(sql) > 0
assert "SELECT" in sql