forked from dbt-labs/dbt-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_main.py
106 lines (84 loc) · 3.5 KB
/
test_main.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
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
98
99
100
101
102
103
104
105
106
import os
import shutil
import tempfile
import unittest
from unittest import mock
import yaml
from dbt import main
class FakeArgs:
def __init__(self, profiles_dir):
self.profiles_dir = profiles_dir
self.profile = 'test'
@mock.patch('dbt.ui.use_colors')
@mock.patch('dbt.tracking.do_not_track')
@mock.patch('dbt.tracking.initialize_tracking')
class TestInitializeConfig(unittest.TestCase):
def setUp(self):
self.base_dir = tempfile.mkdtemp()
self.profiles_path = os.path.join(self.base_dir, 'profiles.yml')
self.args = FakeArgs(self.base_dir)
def _base_config(self):
return {
'test': {
'outputs': {
'default': {
'type': 'postgres',
'host': 'test',
'port': 5555,
'user': 'db_user',
'pass': 'db_pass',
'dbname': 'dbname',
'schema': 'schema',
},
},
'target': 'default',
}
}
def set_up_empty_config(self):
with open(self.profiles_path, 'w') as f:
f.write(yaml.dump(self._base_config()))
def set_up_config_options(self, **kwargs):
config = self._base_config()
config.update(config=kwargs)
with open(self.profiles_path, 'w') as f:
f.write(yaml.dump(config))
def tearDown(self):
try:
shutil.rmtree(self.base_dir)
except:
pass
def test__implicit_missing(self, initialize_tracking, do_not_track, use_colors):
main.initialize_config_values(self.args)
initialize_tracking.assert_called_once_with(self.base_dir)
do_not_track.assert_not_called()
use_colors.assert_not_called()
def test__implicit_opt_in_colors(self, initialize_tracking, do_not_track, use_colors):
self.set_up_empty_config()
main.initialize_config_values(self.args)
initialize_tracking.assert_called_once_with(self.base_dir)
do_not_track.assert_not_called()
use_colors.assert_not_called()
def test__explicit_opt_out(self, initialize_tracking, do_not_track, use_colors):
self.set_up_config_options(send_anonymous_usage_stats=False)
main.initialize_config_values(self.args)
initialize_tracking.assert_not_called()
do_not_track.assert_called_once_with()
use_colors.assert_not_called()
def test__explicit_opt_in(self, initialize_tracking, do_not_track, use_colors):
self.set_up_config_options(send_anonymous_usage_stats=True)
main.initialize_config_values(self.args)
initialize_tracking.assert_called_once_with(self.base_dir)
do_not_track.assert_not_called()
use_colors.assert_not_called()
def test__explicit_no_colors(self, initialize_tracking, do_not_track, use_colors):
self.set_up_config_options(use_colors=False)
main.initialize_config_values(self.args)
initialize_tracking.assert_called_once_with(self.base_dir)
do_not_track.assert_not_called()
use_colors.assert_called_once_with(False)
def test__explicit_yes_colors(self, initialize_tracking, do_not_track, use_colors):
self.set_up_config_options(use_colors=True)
main.initialize_config_values(self.args)
initialize_tracking.assert_called_once_with(self.base_dir)
do_not_track.assert_not_called()
use_colors.assert_called_once_with(True)