11import json
22import os
33
4+ import yaml
45from data_diff .diff_tables import Algorithm
56from .test_cli import run_datadiff_cli
67
@@ -49,112 +50,102 @@ def test_get_datadiff_variables_empty(self):
4950 DbtParser .get_datadiff_variables (mock_self )
5051
5152 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
52- @patch ("data_diff.dbt.parse_run_results" )
53- @patch ("data_diff.dbt.parse_manifest" )
54- def test_get_models (self , mock_manifest_parser , mock_run_parser , mock_open ):
53+ def test_get_models (self , mock_open ):
5554 expected_value = "expected_value"
5655 mock_self = Mock ()
5756 mock_self .project_dir = ""
5857 mock_run_results = Mock ()
5958 mock_success_result = Mock ()
6059 mock_failed_result = Mock ()
6160 mock_manifest = Mock ()
62- mock_run_parser .return_value = mock_run_results
61+ mock_self . parse_run_results .return_value = mock_run_results
6362 mock_run_results .metadata .dbt_version = "1.0.0"
6463 mock_success_result .unique_id = "success_unique_id"
6564 mock_failed_result .unique_id = "failed_unique_id"
6665 mock_success_result .status .name = "success"
6766 mock_failed_result .status .name = "failed"
6867 mock_run_results .results = [mock_success_result , mock_failed_result ]
69- mock_manifest_parser .return_value = mock_manifest
68+ mock_self . parse_manifest .return_value = mock_manifest
7069 mock_manifest .nodes = {"success_unique_id" : expected_value }
7170
7271 models = DbtParser .get_models (mock_self )
7372
7473 self .assertEqual (expected_value , models [0 ])
7574 mock_open .assert_any_call (RUN_RESULTS_PATH )
7675 mock_open .assert_any_call (MANIFEST_PATH )
77- mock_run_parser .assert_called_once_with (run_results = {})
78- mock_manifest_parser .assert_called_once_with (manifest = {})
76+ mock_self . parse_run_results .assert_called_once_with (run_results = {})
77+ mock_self . parse_manifest .assert_called_once_with (manifest = {})
7978
8079 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
81- @patch ("data_diff.dbt.parse_run_results" )
82- @patch ("data_diff.dbt.parse_manifest" )
83- def test_get_models_bad_lower_dbt_version (self , mock_manifest_parser , mock_run_parser , mock_open ):
80+ def test_get_models_bad_lower_dbt_version (self , mock_open ):
8481 mock_self = Mock ()
8582 mock_self .project_dir = ""
8683 mock_run_results = Mock ()
87- mock_run_parser .return_value = mock_run_results
84+ mock_self . parse_run_results .return_value = mock_run_results
8885 mock_run_results .metadata .dbt_version = "0.19.0"
8986
9087 with self .assertRaises (Exception ) as ex :
9188 DbtParser .get_models (mock_self )
9289
9390 mock_open .assert_called_once_with (RUN_RESULTS_PATH )
94- mock_run_parser .assert_called_once_with (run_results = {})
95- mock_manifest_parser .assert_not_called ()
91+ mock_self . parse_run_results .assert_called_once_with (run_results = {})
92+ mock_self . parse_manifest .assert_not_called ()
9693 self .assertIn ("version to be" , ex .exception .args [0 ])
9794
9895 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
99- @patch ("data_diff.dbt.parse_run_results" )
100- @patch ("data_diff.dbt.parse_manifest" )
101- def test_get_models_bad_upper_dbt_version (self , mock_manifest_parser , mock_run_parser , mock_open ):
96+ def test_get_models_bad_upper_dbt_version (self , mock_open ):
10297 mock_self = Mock ()
10398 mock_self .project_dir = ""
10499 mock_run_results = Mock ()
105- mock_run_parser .return_value = mock_run_results
100+ mock_self . parse_run_results .return_value = mock_run_results
106101 mock_run_results .metadata .dbt_version = "1.5.1"
107102
108103 with self .assertRaises (Exception ) as ex :
109104 DbtParser .get_models (mock_self )
110105
111106 mock_open .assert_called_once_with (RUN_RESULTS_PATH )
112- mock_run_parser .assert_called_once_with (run_results = {})
113- mock_manifest_parser .assert_not_called ()
107+ mock_self . parse_run_results .assert_called_once_with (run_results = {})
108+ mock_self . parse_manifest .assert_not_called ()
114109 self .assertIn ("version to be" , ex .exception .args [0 ])
115110
116111 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
117- @patch ("data_diff.dbt.parse_run_results" )
118- @patch ("data_diff.dbt.parse_manifest" )
119- def test_get_models_no_success (self , mock_manifest_parser , mock_run_parser , mock_open ):
112+ def test_get_models_no_success (self , mock_open ):
120113 mock_self = Mock ()
121114 mock_self .project_dir = ""
122115 mock_run_results = Mock ()
123116 mock_success_result = Mock ()
124117 mock_failed_result = Mock ()
125118 mock_manifest = Mock ()
126- mock_run_parser .return_value = mock_run_results
119+ mock_self . parse_run_results .return_value = mock_run_results
127120 mock_run_results .metadata .dbt_version = "1.0.0"
128121 mock_failed_result .unique_id = "failed_unique_id"
129122 mock_success_result .status .name = "success"
130123 mock_failed_result .status .name = "failed"
131124 mock_run_results .results = [mock_failed_result ]
132- mock_manifest_parser .return_value = mock_manifest
125+ mock_self . parse_manifest .return_value = mock_manifest
133126 mock_manifest .nodes = {"success_unique_id" : "a_unique_id" }
134127
135128 with self .assertRaises (Exception ):
136129 DbtParser .get_models (mock_self )
137130
138131 mock_open .assert_any_call (RUN_RESULTS_PATH )
139132 mock_open .assert_any_call (MANIFEST_PATH )
140- mock_run_parser .assert_called_once_with (run_results = {})
141- mock_manifest_parser .assert_called_once_with (manifest = {})
133+ mock_self . parse_run_results .assert_called_once_with (run_results = {})
134+ mock_self . parse_manifest .assert_called_once_with (manifest = {})
142135
143- @patch ("data_diff.dbt.yaml.safe_load" )
144136 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
145- def test_set_project_dict (self , mock_open , mock_yaml_parse ):
137+ def test_set_project_dict (self , mock_open ):
146138 expected_dict = {"key1" : "value1" }
147139 mock_self = Mock ()
148140 mock_self .project_dir = ""
149- mock_yaml_parse .return_value = expected_dict
141+ mock_self . yaml . safe_load .return_value = expected_dict
150142 DbtParser .set_project_dict (mock_self )
151143
152144 self .assertEqual (mock_self .project_dict , expected_dict )
153145 mock_open .assert_called_once_with (PROJECT_FILE )
154146
155- @patch ("data_diff.dbt.yaml.safe_load" )
156147 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
157- def test_set_connection_snowflake (self , mock_open_file , mock_yaml_parse ):
148+ def test_set_connection_snowflake (self , mock_open_file ):
158149 expected_driver = "snowflake"
159150 expected_password = "password_value"
160151 profiles_dict = {
@@ -172,19 +163,19 @@ def test_set_connection_snowflake(self, mock_open_file, mock_yaml_parse):
172163 mock_self = Mock ()
173164 mock_self .profiles_dir = ""
174165 mock_self .project_dict = {"profile" : "profile_name" }
175- mock_yaml_parse .return_value = profiles_dict
166+ mock_self .yaml .safe_load .return_value = profiles_dict
167+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
176168 DbtParser .set_connection (mock_self )
177169
178170 self .assertIsInstance (mock_self .connection , dict )
179171 self .assertEqual (mock_self .connection .get ("driver" ), expected_driver )
180172 self .assertEqual (mock_self .connection .get ("password" ), expected_password )
181173 self .assertEqual (mock_self .requires_upper , True )
182174 mock_open_file .assert_called_once_with (PROFILES_FILE )
183- mock_yaml_parse .assert_called_once_with (mock_open_file ())
175+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
184176
185- @patch ("data_diff.dbt.yaml.safe_load" )
186177 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
187- def test_set_connection_snowflake_no_password (self , mock_open_file , mock_yaml_parse ):
178+ def test_set_connection_snowflake_no_password (self , mock_open_file ):
188179 expected_driver = "snowflake"
189180 profiles_dict = {
190181 "profile_name" : {
@@ -196,18 +187,18 @@ def test_set_connection_snowflake_no_password(self, mock_open_file, mock_yaml_pa
196187 mock_self = Mock ()
197188 mock_self .profiles_dir = ""
198189 mock_self .project_dict = {"profile" : "profile_name" }
199- mock_yaml_parse .return_value = profiles_dict
190+ mock_self .yaml .safe_load .return_value = profiles_dict
191+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
200192
201193 with self .assertRaises (Exception ):
202194 DbtParser .set_connection (mock_self )
203195
204196 mock_open_file .assert_called_once_with (PROFILES_FILE )
205- mock_yaml_parse .assert_called_once_with (mock_open_file ())
197+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
206198 self .assertNotIsInstance (mock_self .connection , dict )
207199
208- @patch ("data_diff.dbt.yaml.safe_load" )
209200 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
210- def test_set_connection_bigquery (self , mock_open_file , mock_yaml_parse ):
201+ def test_set_connection_bigquery (self , mock_open_file ):
211202 expected_driver = "bigquery"
212203 expected_method = "oauth"
213204 expected_project = "a_project"
@@ -229,19 +220,19 @@ def test_set_connection_bigquery(self, mock_open_file, mock_yaml_parse):
229220 mock_self = Mock ()
230221 mock_self .profiles_dir = ""
231222 mock_self .project_dict = {"profile" : "profile_name" }
232- mock_yaml_parse .return_value = profiles_dict
223+ mock_self .yaml .safe_load .return_value = profiles_dict
224+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
233225 DbtParser .set_connection (mock_self )
234226
235227 self .assertIsInstance (mock_self .connection , dict )
236228 self .assertEqual (mock_self .connection .get ("driver" ), expected_driver )
237229 self .assertEqual (mock_self .connection .get ("project" ), expected_project )
238230 self .assertEqual (mock_self .connection .get ("dataset" ), expected_dataset )
239231 mock_open_file .assert_called_once_with (PROFILES_FILE )
240- mock_yaml_parse .assert_called_once_with (mock_open_file ())
232+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
241233
242- @patch ("data_diff.dbt.yaml.safe_load" )
243234 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
244- def test_set_connection_bigquery_not_oauth (self , mock_open_file , mock_yaml_parse ):
235+ def test_set_connection_bigquery_not_oauth (self , mock_open_file ):
245236 expected_driver = "bigquery"
246237 expected_method = "not_oauth"
247238 expected_project = "a_project"
@@ -263,17 +254,17 @@ def test_set_connection_bigquery_not_oauth(self, mock_open_file, mock_yaml_parse
263254 mock_self = Mock ()
264255 mock_self .profiles_dir = ""
265256 mock_self .project_dict = {"profile" : "profile_name" }
266- mock_yaml_parse .return_value = profiles_dict
257+ mock_self .yaml .safe_load .return_value = profiles_dict
258+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
267259 with self .assertRaises (Exception ):
268260 DbtParser .set_connection (mock_self )
269261
270262 mock_open_file .assert_called_once_with (PROFILES_FILE )
271- mock_yaml_parse .assert_called_once_with (mock_open_file ())
263+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
272264 self .assertNotIsInstance (mock_self .connection , dict )
273265
274- @patch ("data_diff.dbt.yaml.safe_load" )
275266 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
276- def test_set_connection_key_error (self , mock_open_file , mock_yaml_parse ):
267+ def test_set_connection_key_error (self , mock_open_file ):
277268 profiles_dict = {
278269 "profile_name" : {
279270 "outputs" : {
@@ -290,17 +281,17 @@ def test_set_connection_key_error(self, mock_open_file, mock_yaml_parse):
290281 mock_self .profiles_dir = ""
291282 mock_self .project_dir = ""
292283 mock_self .project_dict = {"profile" : "bad_key" }
293- mock_yaml_parse .return_value = profiles_dict
284+ mock_self .yaml .safe_load .return_value = profiles_dict
285+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
294286 with self .assertRaises (Exception ):
295287 DbtParser .set_connection (mock_self )
296288
297289 mock_open_file .assert_called_once_with (PROFILES_FILE )
298- mock_yaml_parse .assert_called_once_with (mock_open_file ())
290+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
299291 self .assertNotIsInstance (mock_self .connection , dict )
300292
301- @patch ("data_diff.dbt.yaml.safe_load" )
302293 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
303- def test_set_connection_not_implemented (self , mock_open_file , mock_yaml_parse ):
294+ def test_set_connection_not_implemented (self , mock_open_file ):
304295 expected_driver = "not_implemented"
305296 profiles_dict = {
306297 "profile_name" : {
@@ -317,12 +308,13 @@ def test_set_connection_not_implemented(self, mock_open_file, mock_yaml_parse):
317308 mock_self .profiles_dir = ""
318309 mock_self .project_dir = ""
319310 mock_self .project_dict = {"profile" : "profile_name" }
320- mock_yaml_parse .return_value = profiles_dict
311+ mock_self .yaml .safe_load .return_value = profiles_dict
312+ mock_self .ProfileRenderer ().render_data .return_value = profiles_dict ["profile_name" ]["outputs" ]["connection1" ]
321313 with self .assertRaises (NotImplementedError ):
322314 DbtParser .set_connection (mock_self )
323315
324316 mock_open_file .assert_called_once_with (PROFILES_FILE )
325- mock_yaml_parse .assert_called_once_with (mock_open_file ())
317+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
326318 self .assertNotIsInstance (mock_self .connection , dict )
327319
328320
0 commit comments