-
Notifications
You must be signed in to change notification settings - Fork 39
/
test_dbt_show.py
55 lines (43 loc) · 1.66 KB
/
test_dbt_show.py
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
import pytest
from dbt.tests.adapter.dbt_show import fixtures
from dbt.tests.util import run_dbt
# -- Below we define base classes for tests you import based on if your adapter supports dbt show or not --
class BaseShowLimit:
@pytest.fixture(scope="class")
def models(self):
return {
"sample_model.sql": fixtures.models__sample_model,
"ephemeral_model.sql": fixtures.models__ephemeral_model,
}
@pytest.fixture(scope="class")
def seeds(self):
return {"sample_seed.csv": fixtures.seeds__sample_seed}
@pytest.mark.parametrize(
"args,expected",
[
([], 5), # default limit
(["--limit", 3], 3), # fetch 3 rows
(["--limit", -1], 7), # fetch all rows
],
)
def test_limit(self, project, args, expected):
run_dbt(["build"])
dbt_args = ["show", "--inline", fixtures.models__second_ephemeral_model, *args]
results = run_dbt(dbt_args)
assert len(results.results[0].agate_table) == expected
# ensure limit was injected in compiled_code when limit specified in command args
limit = results.args.get("limit")
if limit > 0:
assert f"limit {limit}" in results.results[0].node.compiled_code
class BaseShowSqlHeader:
@pytest.fixture(scope="class")
def models(self):
return {
"sql_header.sql": fixtures.models__sql_header,
}
def test_sql_header(self, project):
run_dbt(["show", "--select", "sql_header", "--vars", "timezone: Asia/Kolkata"])
class TestPostgresShowSqlHeader(BaseShowSqlHeader):
pass
class TestPostgresShowLimit(BaseShowLimit):
pass