@@ -55,10 +55,23 @@ def mock_cli_console(self):
55
55
with mock .patch ("snowflake.cli.api.console" ) as _fixture :
56
56
yield _fixture
57
57
58
+ @pytest .fixture
59
+ def mock_exists (self ):
60
+ with mock .patch (
61
+ "snowflake.cli._plugins.dbt.manager.DBTManager.exists" , return_value = False
62
+ ) as _fixture :
63
+ yield _fixture
64
+
58
65
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.put_recursive" )
59
66
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.create" )
60
67
def test_deploys_project_from_source (
61
- self , mock_create , mock_put_recursive , mock_connect , runner , dbt_project_path
68
+ self ,
69
+ mock_create ,
70
+ mock_put_recursive ,
71
+ mock_connect ,
72
+ runner ,
73
+ dbt_project_path ,
74
+ mock_exists ,
62
75
):
63
76
64
77
result = runner .invoke (
@@ -88,7 +101,13 @@ def test_deploys_project_from_source(
88
101
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.put_recursive" )
89
102
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.create" )
90
103
def test_dbt_version_from_option_has_precedence_over_file (
91
- self , _mock_create , _mock_put_recursive , mock_connect , runner , dbt_project_path
104
+ self ,
105
+ _mock_create ,
106
+ _mock_put_recursive ,
107
+ mock_connect ,
108
+ runner ,
109
+ dbt_project_path ,
110
+ mock_exists ,
92
111
):
93
112
result = runner .invoke (
94
113
[
@@ -110,11 +129,21 @@ def test_dbt_version_from_option_has_precedence_over_file(
110
129
DBT_ADAPTER_VERSION='3.4.5'"""
111
130
)
112
131
132
+ @pytest .mark .parametrize ("exists" , (True , False ))
113
133
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.put_recursive" )
114
134
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.create" )
115
135
def test_force_flag_uses_create_or_replace (
116
- self , _mock_create , _mock_put_recursive , mock_connect , runner , dbt_project_path
136
+ self ,
137
+ _mock_create ,
138
+ _mock_put_recursive ,
139
+ exists ,
140
+ mock_connect ,
141
+ runner ,
142
+ dbt_project_path ,
143
+ mock_exists ,
117
144
):
145
+ mock_exists .return_value = exists
146
+
118
147
result = runner .invoke (
119
148
[
120
149
"dbt" ,
@@ -134,7 +163,13 @@ def test_force_flag_uses_create_or_replace(
134
163
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.put_recursive" )
135
164
@mock .patch ("snowflake.cli._plugins.dbt.manager.StageManager.create" )
136
165
def test_execute_in_warehouse (
137
- self , _mock_create , _mock_put_recursive , mock_connect , runner , dbt_project_path
166
+ self ,
167
+ _mock_create ,
168
+ _mock_put_recursive ,
169
+ mock_connect ,
170
+ runner ,
171
+ dbt_project_path ,
172
+ mock_exists ,
138
173
):
139
174
140
175
result = runner .invoke (
@@ -201,6 +236,27 @@ def test_raises_when_dbt_project_version_is_not_specified(
201
236
)
202
237
assert mock_connect .mocked_ctx .get_query () == ""
203
238
239
+ def test_raises_when_dbt_project_exists_and_is_not_force (
240
+ self , dbt_project_path , mock_connect , runner , mock_exists
241
+ ):
242
+ mock_exists .return_value = True
243
+
244
+ result = runner .invoke (
245
+ [
246
+ "dbt" ,
247
+ "deploy" ,
248
+ "TEST_PIPELINE" ,
249
+ f"--source={ dbt_project_path } " ,
250
+ ],
251
+ )
252
+
253
+ assert result .exit_code == 1 , result .output
254
+ assert (
255
+ "DBT project TEST_PIPELINE already exists. Use --force flag to overwrite"
256
+ in result .output
257
+ )
258
+ assert mock_connect .mocked_ctx .get_query () == ""
259
+
204
260
205
261
class TestDBTExecute :
206
262
@pytest .mark .parametrize (
0 commit comments