44from data_diff .cloud .datafold_api import TCloudApiDataSource
55from data_diff .cloud .datafold_api import TCloudApiOrgMeta
66from data_diff .diff_tables import Algorithm
7+ from data_diff .errors import DbtBigQueryOauthOnlyError , DbtConnectionNotImplementedError , DbtCoreNoRunnerError , DbtNoSuccessfulModelsInRunError , DbtProfileNotFoundError , DbtProjectVarsNotFoundError , DbtRedshiftPasswordOnlyError , DbtRunResultsVersionError , DbtSelectVersionTooLowError , DbtSnowflakeSetConnectionError
78from .test_cli import run_datadiff_cli
89
910from data_diff .dbt import (
@@ -40,7 +41,7 @@ def test_get_datadiff_variables_none(self):
4041 mock_self = Mock ()
4142 mock_self .project_dict = none_dict
4243
43- with self .assertRaises (Exception ):
44+ with self .assertRaises (DbtProjectVarsNotFoundError ):
4445 DbtParser .get_datadiff_variables (mock_self )
4546
4647 def test_get_datadiff_variables_empty (self ):
@@ -49,7 +50,7 @@ def test_get_datadiff_variables_empty(self):
4950 mock_self = Mock ()
5051 mock_self .project_dict = empty_dict
5152
52- with self .assertRaises (Exception ):
53+ with self .assertRaises (DbtProjectVarsNotFoundError ):
5354 DbtParser .get_datadiff_variables (mock_self )
5455
5556 def test_get_models (self ):
@@ -72,7 +73,7 @@ def test_get_models_unsupported_manifest_version(self):
7273 mock_return_value = Mock ()
7374 mock_self .get_dbt_selection_models .return_value = mock_return_value
7475
75- with self .assertRaises (Exception ):
76+ with self .assertRaises (DbtSelectVersionTooLowError ):
7677 _ = DbtParser .get_models (mock_self , selection )
7778 mock_self .get_dbt_selection_models .assert_not_called ()
7879
@@ -85,7 +86,7 @@ def test_get_models_no_runner(self):
8586 mock_return_value = Mock ()
8687 mock_self .get_dbt_selection_models .return_value = mock_return_value
8788
88- with self .assertRaises (Exception ):
89+ with self .assertRaises (DbtCoreNoRunnerError ):
8990 _ = DbtParser .get_models (mock_self , selection )
9091 mock_self .get_dbt_selection_models .assert_not_called ()
9192
@@ -135,7 +136,7 @@ def test_get_run_results_models_bad_lower_dbt_version(self, mock_open, mock_arti
135136 mock_artifact_parser .return_value = mock_run_results
136137 mock_run_results .metadata .dbt_version = "0.19.0"
137138
138- with self .assertRaises (Exception ) as ex :
139+ with self .assertRaises (DbtRunResultsVersionError ) as ex :
139140 DbtParser .get_run_results_models (mock_self )
140141
141142 mock_open .assert_called_once_with (Path (RUN_RESULTS_PATH ))
@@ -158,7 +159,7 @@ def test_get_run_results_models_no_success(self, mock_open, mock_artifact_parser
158159 mock_failed_result .status .name = "failed"
159160 mock_run_results .results = [mock_failed_result ]
160161
161- with self .assertRaises (Exception ):
162+ with self .assertRaises (DbtNoSuccessfulModelsInRunError ):
162163 DbtParser .get_run_results_models (mock_self )
163164
164165 mock_open .assert_any_call (Path (RUN_RESULTS_PATH ))
@@ -235,7 +236,7 @@ def test_set_connection_snowflake_no_key_or_password(self):
235236 mock_self = Mock ()
236237 mock_self .get_connection_creds .return_value = (expected_credentials , expected_driver )
237238
238- with self .assertRaises (Exception ):
239+ with self .assertRaises (DbtSnowflakeSetConnectionError ):
239240 DbtParser .set_connection (mock_self )
240241
241242 self .assertNotIsInstance (mock_self .connection , dict )
@@ -259,7 +260,7 @@ def test_set_connection_snowflake_key_and_password(self):
259260 mock_self = Mock ()
260261 mock_self .get_connection_creds .return_value = (expected_credentials , expected_driver )
261262
262- with self .assertRaises (Exception ):
263+ with self .assertRaises (DbtSnowflakeSetConnectionError ):
263264 DbtParser .set_connection (mock_self )
264265
265266 self .assertNotIsInstance (mock_self .connection , dict )
@@ -291,7 +292,20 @@ def test_set_connection_bigquery_not_oauth(self):
291292
292293 mock_self = Mock ()
293294 mock_self .get_connection_creds .return_value = (expected_credentials , expected_driver )
294- with self .assertRaises (Exception ):
295+ with self .assertRaises (DbtBigQueryOauthOnlyError ):
296+ DbtParser .set_connection (mock_self )
297+
298+ self .assertNotIsInstance (mock_self .connection , dict )
299+
300+ def test_set_connection_redshift_not_password (self ):
301+ driver = "redshift"
302+ credentials = {
303+ "method" : "not_password" ,
304+ }
305+
306+ mock_self = Mock ()
307+ mock_self .get_connection_creds .return_value = (credentials , driver )
308+ with self .assertRaises (DbtRedshiftPasswordOnlyError ):
295309 DbtParser .set_connection (mock_self )
296310
297311 self .assertNotIsInstance (mock_self .connection , dict )
@@ -301,7 +315,7 @@ def test_set_connection_not_implemented(self):
301315
302316 mock_self = Mock ()
303317 mock_self .get_connection_creds .return_value = (None , expected_driver )
304- with self .assertRaises (NotImplementedError ):
318+ with self .assertRaises (DbtConnectionNotImplementedError ):
305319 DbtParser .set_connection (mock_self )
306320
307321 self .assertNotIsInstance (mock_self .connection , dict )
@@ -340,7 +354,7 @@ def test_get_connection_no_matching_profile(self, mock_open, mock_profile_render
340354 mock_yaml .safe_load .return_value = profiles_dict
341355 profile = profiles_dict ["a_profile" ]
342356 mock_profile_renderer ().render_data .return_value = profile
343- with self .assertRaises (ValueError ):
357+ with self .assertRaises (DbtProfileNotFoundError ):
344358 _ , _ = DbtParser .get_connection_creds (mock_self )
345359
346360 @patch ("data_diff.dbt_parser.yaml" )
@@ -360,7 +374,7 @@ def test_get_connection_no_target(self, mock_open, mock_profile_renderer, mock_y
360374 mock_profile_renderer ().render_data .return_value = profile
361375 mock_self .project_dict = {"profile" : "a_profile" }
362376 mock_yaml .safe_load .return_value = profiles_dict
363- with self .assertRaises (ValueError ):
377+ with self .assertRaises (DbtProfileNotFoundError ):
364378 _ , _ = DbtParser .get_connection_creds (mock_self )
365379
366380 profile_yaml_no_outputs = """
@@ -379,7 +393,7 @@ def test_get_connection_no_outputs(self, mock_open, mock_profile_renderer, mock_
379393 profile = profiles_dict ["a_profile" ]
380394 mock_profile_renderer ().render_data .return_value = profile
381395 mock_yaml .safe_load .return_value = profiles_dict
382- with self .assertRaises (ValueError ):
396+ with self .assertRaises (DbtProfileNotFoundError ):
383397 _ , _ = DbtParser .get_connection_creds (mock_self )
384398
385399 @patch ("data_diff.dbt_parser.yaml" )
@@ -398,7 +412,7 @@ def test_get_connection_no_credentials(self, mock_open, mock_profile_renderer, m
398412 mock_yaml .safe_load .return_value = profiles_dict
399413 profile = profiles_dict ["a_profile" ]
400414 mock_profile_renderer ().render_data .return_value = profile
401- with self .assertRaises (ValueError ):
415+ with self .assertRaises (DbtProfileNotFoundError ):
402416 _ , _ = DbtParser .get_connection_creds (mock_self )
403417
404418 @patch ("data_diff.dbt_parser.yaml" )
@@ -419,7 +433,7 @@ def test_get_connection_no_target_credentials(self, mock_open, mock_profile_rend
419433 profile = profiles_dict ["a_profile" ]
420434 mock_profile_renderer ().render_data .return_value = profile
421435 mock_yaml .safe_load .return_value = profiles_dict
422- with self .assertRaises (ValueError ):
436+ with self .assertRaises (DbtProfileNotFoundError ):
423437 _ , _ = DbtParser .get_connection_creds (mock_self )
424438
425439 @patch ("data_diff.dbt_parser.yaml" )
@@ -438,7 +452,7 @@ def test_get_connection_no_type(self, mock_open, mock_profile_renderer, mock_yam
438452 mock_yaml .safe_load .return_value = profiles_dict
439453 profile = profiles_dict ["a_profile" ]
440454 mock_profile_renderer ().render_data .return_value = profile
441- with self .assertRaises (ValueError ):
455+ with self .assertRaises (DbtProfileNotFoundError ):
442456 _ , _ = DbtParser .get_connection_creds (mock_self )
443457
444458
0 commit comments