@@ -51,8 +51,58 @@ def test_get_datadiff_variables_empty(self):
5151 with self .assertRaises (Exception ):
5252 DbtParser .get_datadiff_variables (mock_self )
5353
54+ def test_get_models (self ):
55+ mock_self = Mock ()
56+ mock_self .project_dir = Path ()
57+ mock_self .dbt_version = "1.5.0"
58+ selection = "model+"
59+ mock_return_value = Mock ()
60+ mock_self .get_dbt_selection_models .return_value = mock_return_value
61+
62+ models = DbtParser .get_models (mock_self , selection )
63+ mock_self .get_dbt_selection_models .assert_called_once_with (selection )
64+ self .assertEqual (models , mock_return_value )
65+
66+ def test_get_models_unsupported_manifest_version (self ):
67+ mock_self = Mock ()
68+ mock_self .project_dir = Path ()
69+ mock_self .dbt_version = "1.4.0"
70+ selection = "model+"
71+ mock_return_value = Mock ()
72+ mock_self .get_dbt_selection_models .return_value = mock_return_value
73+
74+ with self .assertRaises (Exception ):
75+ _ = DbtParser .get_models (mock_self , selection )
76+ mock_self .get_dbt_selection_models .assert_not_called ()
77+
78+ def test_get_models_no_runner (self ):
79+ mock_self = Mock ()
80+ mock_self .project_dir = Path ()
81+ mock_self .dbt_version = "1.5.0"
82+ mock_self .dbt_runner = None
83+ selection = "model+"
84+ mock_return_value = Mock ()
85+ mock_self .get_dbt_selection_models .return_value = mock_return_value
86+
87+ with self .assertRaises (Exception ):
88+ _ = DbtParser .get_models (mock_self , selection )
89+ mock_self .get_dbt_selection_models .assert_not_called ()
90+
91+ def test_get_models_no_selection (self ):
92+ mock_self = Mock ()
93+ mock_self .project_dir = Path ()
94+ mock_self .dbt_version = "1.5.0"
95+ selection = None
96+ mock_return_value = Mock ()
97+ mock_self .get_run_results_models .return_value = mock_return_value
98+
99+ models = DbtParser .get_models (mock_self , selection )
100+ mock_self .get_dbt_selection_models .assert_not_called ()
101+ mock_self .get_run_results_models .assert_called ()
102+ self .assertEqual (models , mock_return_value )
103+
54104 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
55- def test_get_models (self , mock_open ):
105+ def test_get_run_results_models (self , mock_open ):
56106 mock_model = {"success_unique_id" : "expected_value" }
57107 mock_self = Mock ()
58108 mock_self .project_dir = Path ()
@@ -68,30 +118,30 @@ def test_get_models(self, mock_open):
68118 mock_run_results .results = [mock_success_result , mock_failed_result ]
69119 mock_self .manifest_obj .nodes .get .return_value = mock_model
70120
71- models = DbtParser .get_models (mock_self )
121+ models = DbtParser .get_run_results_models (mock_self )
72122
73123 self .assertEqual (mock_model , models [0 ])
74124 mock_open .assert_any_call (Path (RUN_RESULTS_PATH ))
75125 mock_self .parse_run_results .assert_called_once_with (run_results = {})
76126
77127 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
78- def test_get_models_bad_lower_dbt_version (self , mock_open ):
128+ def test_get_run_results_models_bad_lower_dbt_version (self , mock_open ):
79129 mock_self = Mock ()
80130 mock_self .project_dir = Path ()
81131 mock_run_results = Mock ()
82132 mock_self .parse_run_results .return_value = mock_run_results
83133 mock_run_results .metadata .dbt_version = "0.19.0"
84134
85135 with self .assertRaises (Exception ) as ex :
86- DbtParser .get_models (mock_self )
136+ DbtParser .get_run_results_models (mock_self )
87137
88138 mock_open .assert_called_once_with (Path (RUN_RESULTS_PATH ))
89139 mock_self .parse_run_results .assert_called_once_with (run_results = {})
90140 mock_self .parse_manifest .assert_not_called ()
91141 self .assertIn ("version to be" , ex .exception .args [0 ])
92142
93143 @patch ("builtins.open" , new_callable = mock_open , read_data = "{}" )
94- def test_get_models_no_success (self , mock_open ):
144+ def test_get_run_results_models_no_success (self , mock_open ):
95145 mock_self = Mock ()
96146 mock_self .project_dir = Path ()
97147 mock_run_results = Mock ()
@@ -105,7 +155,7 @@ def test_get_models_no_success(self, mock_open):
105155 mock_run_results .results = [mock_failed_result ]
106156
107157 with self .assertRaises (Exception ):
108- DbtParser .get_models (mock_self )
158+ DbtParser .get_run_results_models (mock_self )
109159
110160 mock_open .assert_any_call (Path (RUN_RESULTS_PATH ))
111161 mock_self .parse_run_results .assert_called_once_with (run_results = {})
0 commit comments