@@ -51,8 +51,58 @@ def test_get_datadiff_variables_empty(self):
51
51
with self .assertRaises (Exception ):
52
52
DbtParser .get_datadiff_variables (mock_self )
53
53
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
+
54
104
@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 ):
56
106
mock_model = {"success_unique_id" : "expected_value" }
57
107
mock_self = Mock ()
58
108
mock_self .project_dir = Path ()
@@ -68,30 +118,30 @@ def test_get_models(self, mock_open):
68
118
mock_run_results .results = [mock_success_result , mock_failed_result ]
69
119
mock_self .manifest_obj .nodes .get .return_value = mock_model
70
120
71
- models = DbtParser .get_models (mock_self )
121
+ models = DbtParser .get_run_results_models (mock_self )
72
122
73
123
self .assertEqual (mock_model , models [0 ])
74
124
mock_open .assert_any_call (Path (RUN_RESULTS_PATH ))
75
125
mock_self .parse_run_results .assert_called_once_with (run_results = {})
76
126
77
127
@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 ):
79
129
mock_self = Mock ()
80
130
mock_self .project_dir = Path ()
81
131
mock_run_results = Mock ()
82
132
mock_self .parse_run_results .return_value = mock_run_results
83
133
mock_run_results .metadata .dbt_version = "0.19.0"
84
134
85
135
with self .assertRaises (Exception ) as ex :
86
- DbtParser .get_models (mock_self )
136
+ DbtParser .get_run_results_models (mock_self )
87
137
88
138
mock_open .assert_called_once_with (Path (RUN_RESULTS_PATH ))
89
139
mock_self .parse_run_results .assert_called_once_with (run_results = {})
90
140
mock_self .parse_manifest .assert_not_called ()
91
141
self .assertIn ("version to be" , ex .exception .args [0 ])
92
142
93
143
@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 ):
95
145
mock_self = Mock ()
96
146
mock_self .project_dir = Path ()
97
147
mock_run_results = Mock ()
@@ -105,7 +155,7 @@ def test_get_models_no_success(self, mock_open):
105
155
mock_run_results .results = [mock_failed_result ]
106
156
107
157
with self .assertRaises (Exception ):
108
- DbtParser .get_models (mock_self )
158
+ DbtParser .get_run_results_models (mock_self )
109
159
110
160
mock_open .assert_any_call (Path (RUN_RESULTS_PATH ))
111
161
mock_self .parse_run_results .assert_called_once_with (run_results = {})
0 commit comments