@@ -77,83 +77,75 @@ def test_get_models(self, mock_open):
7777 mock_self .parse_manifest .assert_called_once_with (manifest = {})
7878
7979 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
80- @patch ("dbt_artifacts_parser.parser.parse_run_results" )
81- @patch ("dbt_artifacts_parser.parser.parse_manifest" )
82- 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 ):
8381 mock_self = Mock ()
8482 mock_self .project_dir = ""
8583 mock_run_results = Mock ()
86- mock_run_parser .return_value = mock_run_results
84+ mock_self . parse_run_results .return_value = mock_run_results
8785 mock_run_results .metadata .dbt_version = "0.19.0"
8886
8987 with self .assertRaises (Exception ) as ex :
9088 DbtParser .get_models (mock_self )
9189
9290 mock_open .assert_called_once_with (RUN_RESULTS_PATH )
93- mock_run_parser .assert_called_once_with (run_results = {})
94- 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 ()
9593 self .assertIn ("version to be" , ex .exception .args [0 ])
9694
9795 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
98- @patch ("dbt_artifacts_parser.parser.parse_run_results" )
99- @patch ("dbt_artifacts_parser.parser.parse_manifest" )
100- 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 ):
10197 mock_self = Mock ()
10298 mock_self .project_dir = ""
10399 mock_run_results = Mock ()
104- mock_run_parser .return_value = mock_run_results
100+ mock_self . parse_run_results .return_value = mock_run_results
105101 mock_run_results .metadata .dbt_version = "1.5.1"
106102
107103 with self .assertRaises (Exception ) as ex :
108104 DbtParser .get_models (mock_self )
109105
110106 mock_open .assert_called_once_with (RUN_RESULTS_PATH )
111- mock_run_parser .assert_called_once_with (run_results = {})
112- 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 ()
113109 self .assertIn ("version to be" , ex .exception .args [0 ])
114110
115111 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
116- @patch ("dbt_artifacts_parser.parser.parse_run_results" )
117- @patch ("dbt_artifacts_parser.parser.parse_manifest" )
118- 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 ):
119113 mock_self = Mock ()
120114 mock_self .project_dir = ""
121115 mock_run_results = Mock ()
122116 mock_success_result = Mock ()
123117 mock_failed_result = Mock ()
124118 mock_manifest = Mock ()
125- mock_run_parser .return_value = mock_run_results
119+ mock_self . parse_run_results .return_value = mock_run_results
126120 mock_run_results .metadata .dbt_version = "1.0.0"
127121 mock_failed_result .unique_id = "failed_unique_id"
128122 mock_success_result .status .name = "success"
129123 mock_failed_result .status .name = "failed"
130124 mock_run_results .results = [mock_failed_result ]
131- mock_manifest_parser .return_value = mock_manifest
125+ mock_self . parse_manifest .return_value = mock_manifest
132126 mock_manifest .nodes = {"success_unique_id" : "a_unique_id" }
133127
134128 with self .assertRaises (Exception ):
135129 DbtParser .get_models (mock_self )
136130
137131 mock_open .assert_any_call (RUN_RESULTS_PATH )
138132 mock_open .assert_any_call (MANIFEST_PATH )
139- mock_run_parser .assert_called_once_with (run_results = {})
140- 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 = {})
141135
142- @patch ("yaml.safe_load" )
143136 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
144- def test_set_project_dict (self , mock_open , mock_yaml_parse ):
137+ def test_set_project_dict (self , mock_open ):
145138 expected_dict = {"key1" : "value1" }
146139 mock_self = Mock ()
147140 mock_self .project_dir = ""
148- mock_yaml_parse .return_value = expected_dict
141+ mock_self . yaml . safe_load .return_value = expected_dict
149142 DbtParser .set_project_dict (mock_self )
150143
151144 self .assertEqual (mock_self .project_dict , expected_dict )
152145 mock_open .assert_called_once_with (PROJECT_FILE )
153146
154- @patch ("yaml.safe_load" )
155147 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
156- def test_set_connection_snowflake (self , mock_open_file , mock_yaml_parse ):
148+ def test_set_connection_snowflake (self , mock_open_file ):
157149 expected_driver = "snowflake"
158150 expected_password = "password_value"
159151 profiles_dict = {
@@ -171,19 +163,19 @@ def test_set_connection_snowflake(self, mock_open_file, mock_yaml_parse):
171163 mock_self = Mock ()
172164 mock_self .profiles_dir = ""
173165 mock_self .project_dict = {"profile" : "profile_name" }
174- 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" ]
175168 DbtParser .set_connection (mock_self )
176169
177170 self .assertIsInstance (mock_self .connection , dict )
178171 self .assertEqual (mock_self .connection .get ("driver" ), expected_driver )
179172 self .assertEqual (mock_self .connection .get ("password" ), expected_password )
180173 self .assertEqual (mock_self .requires_upper , True )
181174 mock_open_file .assert_called_once_with (PROFILES_FILE )
182- mock_yaml_parse .assert_called_once_with (mock_open_file ())
175+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
183176
184- @patch ("yaml.safe_load" )
185177 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
186- 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 ):
187179 expected_driver = "snowflake"
188180 profiles_dict = {
189181 "profile_name" : {
@@ -195,18 +187,18 @@ def test_set_connection_snowflake_no_password(self, mock_open_file, mock_yaml_pa
195187 mock_self = Mock ()
196188 mock_self .profiles_dir = ""
197189 mock_self .project_dict = {"profile" : "profile_name" }
198- 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" ]
199192
200193 with self .assertRaises (Exception ):
201194 DbtParser .set_connection (mock_self )
202195
203196 mock_open_file .assert_called_once_with (PROFILES_FILE )
204- mock_yaml_parse .assert_called_once_with (mock_open_file ())
197+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
205198 self .assertNotIsInstance (mock_self .connection , dict )
206199
207- @patch ("yaml.safe_load" )
208200 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
209- def test_set_connection_bigquery (self , mock_open_file , mock_yaml_parse ):
201+ def test_set_connection_bigquery (self , mock_open_file ):
210202 expected_driver = "bigquery"
211203 expected_method = "oauth"
212204 expected_project = "a_project"
@@ -228,19 +220,19 @@ def test_set_connection_bigquery(self, mock_open_file, mock_yaml_parse):
228220 mock_self = Mock ()
229221 mock_self .profiles_dir = ""
230222 mock_self .project_dict = {"profile" : "profile_name" }
231- 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" ]
232225 DbtParser .set_connection (mock_self )
233226
234227 self .assertIsInstance (mock_self .connection , dict )
235228 self .assertEqual (mock_self .connection .get ("driver" ), expected_driver )
236229 self .assertEqual (mock_self .connection .get ("project" ), expected_project )
237230 self .assertEqual (mock_self .connection .get ("dataset" ), expected_dataset )
238231 mock_open_file .assert_called_once_with (PROFILES_FILE )
239- mock_yaml_parse .assert_called_once_with (mock_open_file ())
232+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
240233
241- @patch ("yaml.safe_load" )
242234 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
243- 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 ):
244236 expected_driver = "bigquery"
245237 expected_method = "not_oauth"
246238 expected_project = "a_project"
@@ -262,17 +254,17 @@ def test_set_connection_bigquery_not_oauth(self, mock_open_file, mock_yaml_parse
262254 mock_self = Mock ()
263255 mock_self .profiles_dir = ""
264256 mock_self .project_dict = {"profile" : "profile_name" }
265- 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" ]
266259 with self .assertRaises (Exception ):
267260 DbtParser .set_connection (mock_self )
268261
269262 mock_open_file .assert_called_once_with (PROFILES_FILE )
270- mock_yaml_parse .assert_called_once_with (mock_open_file ())
263+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
271264 self .assertNotIsInstance (mock_self .connection , dict )
272265
273- @patch ("yaml.safe_load" )
274266 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
275- def test_set_connection_key_error (self , mock_open_file , mock_yaml_parse ):
267+ def test_set_connection_key_error (self , mock_open_file ):
276268 profiles_dict = {
277269 "profile_name" : {
278270 "outputs" : {
@@ -289,17 +281,17 @@ def test_set_connection_key_error(self, mock_open_file, mock_yaml_parse):
289281 mock_self .profiles_dir = ""
290282 mock_self .project_dir = ""
291283 mock_self .project_dict = {"profile" : "bad_key" }
292- 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" ]
293286 with self .assertRaises (Exception ):
294287 DbtParser .set_connection (mock_self )
295288
296289 mock_open_file .assert_called_once_with (PROFILES_FILE )
297- mock_yaml_parse .assert_called_once_with (mock_open_file ())
290+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
298291 self .assertNotIsInstance (mock_self .connection , dict )
299292
300- @patch ("yaml.safe_load" )
301293 @patch ("builtins.open" , new_callable = mock_open , read_data = "key:\n value" )
302- def test_set_connection_not_implemented (self , mock_open_file , mock_yaml_parse ):
294+ def test_set_connection_not_implemented (self , mock_open_file ):
303295 expected_driver = "not_implemented"
304296 profiles_dict = {
305297 "profile_name" : {
@@ -316,12 +308,13 @@ def test_set_connection_not_implemented(self, mock_open_file, mock_yaml_parse):
316308 mock_self .profiles_dir = ""
317309 mock_self .project_dir = ""
318310 mock_self .project_dict = {"profile" : "profile_name" }
319- 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" ]
320313 with self .assertRaises (NotImplementedError ):
321314 DbtParser .set_connection (mock_self )
322315
323316 mock_open_file .assert_called_once_with (PROFILES_FILE )
324- mock_yaml_parse .assert_called_once_with (mock_open_file ())
317+ mock_self . yaml . safe_load .assert_called_once_with (mock_open_file ())
325318 self .assertNotIsInstance (mock_self .connection , dict )
326319
327320
0 commit comments