Skip to content

Commit a403453

Browse files
test: [SNOW-1890085] add integration test for simple dbt workflow
1 parent 7ee459e commit a403453

File tree

6 files changed

+135
-0
lines changed

6 files changed

+135
-0
lines changed

tests_integration/conftest.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,19 @@ def invoke_with_connection(
185185
) -> CommandResult:
186186
return self.invoke_with_config([*args, "-c", connection], **kwargs)
187187

188+
def invoke_passthrough_with_connection(
189+
self,
190+
args,
191+
connection: str = "integration",
192+
passthrough_args: Optional[list[str]] = None,
193+
**kwargs,
194+
) -> CommandResult:
195+
if passthrough_args is None:
196+
passthrough_args = list()
197+
return self.invoke_with_config(
198+
[*args, "-c", connection, *passthrough_args], **kwargs
199+
)
200+
188201

189202
@pytest.fixture
190203
def runner(test_snowcli_config_provider, default_username, resource_suffix):
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: 'dbt_integration_project'
2+
version: '1.0.0'
3+
4+
profile: 'dbt_integration_project'
5+
6+
model-paths: ["models"]
7+
analysis-paths: ["analyses"]
8+
test-paths: ["tests"]
9+
seed-paths: ["seeds"]
10+
macro-paths: ["macros"]
11+
snapshot-paths: ["snapshots"]
12+
13+
clean-targets:
14+
- "target"
15+
- "dbt_packages"
16+
17+
models:
18+
dbt_integration_project:
19+
example:
20+
+materialized: view
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{{ config(materialized='table') }}
2+
3+
with source_data as (
4+
select 1 as id
5+
union all
6+
select null as id
7+
)
8+
9+
select *
10+
from source_data
11+
where id is not null
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
select *
2+
from {{ ref('my_first_dbt_model') }}
3+
where id = 1
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
version: 2
3+
4+
models:
5+
- name: my_first_dbt_model
6+
description: "A starter dbt model"
7+
columns:
8+
- name: id
9+
description: "The primary key for this table"
10+
data_tests:
11+
- unique
12+
- not_null
13+
14+
- name: my_second_dbt_model
15+
description: "A starter dbt model"
16+
columns:
17+
- name: id
18+
description: "The primary key for this table"
19+
data_tests:
20+
- unique
21+
- not_null

tests_integration/test_dbt.py

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Copyright (c) 2025 Snowflake Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
import datetime
15+
16+
import pytest
17+
18+
19+
@pytest.mark.integration
20+
@pytest.mark.qa_only
21+
def test_dbt_deploy(
22+
runner,
23+
snowflake_session,
24+
test_database,
25+
project_directory,
26+
):
27+
with project_directory("dbt_project"):
28+
# Given a local dbt project
29+
ts = int(datetime.datetime.now().timestamp())
30+
name = f"dbt_project_{ts}"
31+
32+
# When it's deployed
33+
result = runner.invoke_with_connection_json(["dbt", "deploy", name])
34+
assert result.exit_code == 0, result.output
35+
36+
# Then it can be listed
37+
result = runner.invoke_with_connection_json(
38+
[
39+
"dbt",
40+
"list",
41+
"--like",
42+
name,
43+
]
44+
)
45+
assert result.exit_code == 0, result.output
46+
assert len(result.json) == 1
47+
dbt_object = result.json[0]
48+
assert dbt_object["name"].lower() == name.lower()
49+
50+
# And when dbt run gets called on it
51+
result = runner.invoke_passthrough_with_connection(
52+
args=[
53+
"dbt",
54+
"execute",
55+
],
56+
passthrough_args=[name, "run"],
57+
)
58+
59+
# Then is succeeds and models get populated according to expectations
60+
assert result.exit_code == 0, result.output
61+
assert "Done. PASS=2 WARN=0 ERROR=0 SKIP=0 TOTAL=2" in result.output
62+
63+
result = runner.invoke_with_connection_json(
64+
["sql", "-q", "select count(*) as COUNT from my_second_dbt_model;"]
65+
)
66+
assert len(result.json) == 1, result.json
67+
assert result.json[0]["COUNT"] == 1, result.json[0]

0 commit comments

Comments
 (0)