Skip to content

Commit 72287a4

Browse files
authored
Merge pull request #363 from dbt-msft/debug-test
add debug tests
2 parents 874ea3f + 54eb230 commit 72287a4

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
import os
2+
import re
3+
4+
import yaml
5+
from dbt.tests.adapter.dbt_debug.test_dbt_debug import BaseDebug, BaseDebugProfileVariable
6+
from dbt.tests.util import run_dbt
7+
8+
9+
class TestDebugSQLServer(BaseDebug):
10+
def test_ok(self, project):
11+
run_dbt(["debug"])
12+
assert "ERROR" not in self.capsys.readouterr().out
13+
14+
def test_nopass(self, project):
15+
run_dbt(["debug", "--target", "nopass"], expect_pass=False)
16+
self.assertGotValue(re.compile(r"\s+profiles\.yml file"), "ERROR invalid")
17+
18+
def test_wronguser(self, project):
19+
run_dbt(["debug", "--target", "wronguser"], expect_pass=False)
20+
self.assertGotValue(re.compile(r"\s+Connection test"), "ERROR")
21+
22+
def test_empty_target(self, project):
23+
run_dbt(["debug", "--target", "none_target"], expect_pass=False)
24+
self.assertGotValue(re.compile(r"\s+output 'none_target'"), "misconfigured")
25+
26+
27+
class TestDebugProfileVariableSQLServer(BaseDebugProfileVariable):
28+
pass
29+
30+
31+
class TestDebugInvalidProjectSQLServer(BaseDebug):
32+
def test_empty_project(self, project):
33+
with open("dbt_project.yml", "w") as f: # noqa: F841
34+
pass
35+
36+
run_dbt(["debug", "--profile", "test"], expect_pass=False)
37+
splitout = self.capsys.readouterr().out.split("\n")
38+
self.check_project(splitout)
39+
40+
def test_badproject(self, project):
41+
update_project = {"invalid-key": "not a valid key so this is bad project"}
42+
43+
with open("dbt_project.yml", "w") as f:
44+
yaml.safe_dump(update_project, f)
45+
46+
run_dbt(["debug", "--profile", "test"], expect_pass=False)
47+
splitout = self.capsys.readouterr().out.split("\n")
48+
self.check_project(splitout)
49+
50+
def test_not_found_project(self, project):
51+
run_dbt(["debug", "--project-dir", "nopass"], expect_pass=False)
52+
splitout = self.capsys.readouterr().out.split("\n")
53+
self.check_project(splitout, msg="ERROR not found")
54+
55+
def test_invalid_project_outside_current_dir(self, project):
56+
# create a dbt_project.yml
57+
project_config = {"invalid-key": "not a valid key in this project"}
58+
os.makedirs("custom", exist_ok=True)
59+
with open("custom/dbt_project.yml", "w") as f:
60+
yaml.safe_dump(project_config, f, default_flow_style=True)
61+
run_dbt(["debug", "--project-dir", "custom"], expect_pass=False)
62+
splitout = self.capsys.readouterr().out.split("\n")
63+
self.check_project(splitout)

0 commit comments

Comments
 (0)