@@ -94,47 +94,74 @@ def test_apply_single_resource(patch_click, mocker, resource_was_created):
94
94
95
95
96
96
@pytest .mark .parametrize (
97
- "diff, local_file_changed,force,expected_should_update,expected_update_reason " ,
97
+ "force,user_validation, local_file_changed,expect_update,expected_reason " ,
98
98
[
99
- ( True , True , True , True , "🚨 - Running update because force mode is on." ), # check if force has the top priority
100
- ( True , False , True , True , "🚨 - Running update because force mode is on." ), # check if force has the top priority
101
- ( True , False , False , True , "🚨 - Running update because force mode is on." ), # check if force has the top priority
102
- ( True , True , False , True , "🚨 - Running update because force mode is on." ), # check if force has the top priority
103
- (
99
+ pytest . param (
100
+ True , True , True , True , "🚨 - Running update because the force mode is activated." , id = "1 - Check if force has the top priority."
101
+ ),
102
+ pytest . param (
103
+ True ,
104
104
False ,
105
105
True ,
106
106
True ,
107
+ "🚨 - Running update because the force mode is activated." ,
108
+ id = "2 - Check if force has the top priority." ,
109
+ ),
110
+ pytest .param (
107
111
True ,
108
- "✍️ - Running update because a diff was detected between local and remote resource." ,
109
- ), # check if diff has priority of file changed
110
- (
111
112
False ,
112
- True ,
113
113
False ,
114
114
True ,
115
- "✍️ - Running update because a diff was detected between local and remote resource." ,
116
- ), # check if diff has priority of file changed
117
- (
115
+ "🚨 - Running update because the force mode is activated." ,
116
+ id = "3 - Check if force has the top priority." ,
117
+ ),
118
+ pytest .param (
119
+ True ,
120
+ True ,
118
121
False ,
122
+ True ,
123
+ "🚨 - Running update because the force mode is activated." ,
124
+ id = "4 - Check if force has the top priority." ,
125
+ ),
126
+ pytest .param (
119
127
False ,
120
128
True ,
121
129
True ,
122
- "✍️ - Running update because a local file change was detected and a secret field might have been edited." ,
123
- ), # check if local_file_changed runs even if no diff found
124
- (
130
+ True ,
131
+ "🟢 - Running update because you validated the changes." ,
132
+ id = "Check if user validation has priority over local file change." ,
133
+ ),
134
+ pytest .param (
125
135
False ,
126
136
False ,
137
+ True ,
138
+ False ,
139
+ "🔴 - Did not update because you refused the changes." ,
140
+ id = "Check if user validation has priority over local file change." ,
141
+ ),
142
+ pytest .param (
143
+ False ,
144
+ None ,
145
+ True ,
146
+ True ,
147
+ "🟡 - Running update because a local file change was detected and a secret field might have been edited." ,
148
+ id = "Check if local_file_changed runs even if user validation is None." ,
149
+ ),
150
+ pytest .param (
151
+ False ,
152
+ None ,
127
153
False ,
128
154
False ,
129
155
"😴 - Did not update because no change detected." ,
130
- ), # check if local_file_changed runs even if no diff found
156
+ id = "Check no update if no local change and user validation is None." ,
157
+ ),
131
158
],
132
159
)
133
- def test_should_update_resource (patch_click , mocker , diff , local_file_changed , force , expected_should_update , expected_update_reason ):
134
- should_update , update_reason = commands .should_update_resource (diff , local_file_changed , force )
135
- assert should_update == expected_should_update
160
+ def test_should_update_resource (patch_click , mocker , force , user_validation , local_file_changed , expect_update , expected_reason ):
161
+ should_update , update_reason = commands .should_update_resource (force , user_validation , local_file_changed )
162
+ assert should_update == expect_update
136
163
assert update_reason == commands .click .style .return_value
137
- commands .click .style .assert_called_with (expected_update_reason , fg = "green" )
164
+ commands .click .style .assert_called_with (expected_reason , fg = "green" )
138
165
139
166
140
167
@pytest .mark .parametrize (
@@ -177,80 +204,52 @@ def test_create_resource(patch_click, mocker):
177
204
178
205
179
206
@pytest .mark .parametrize (
180
- "force,diff,should_update_resource ,expect_prompt,user_validate_diff ,expect_update,expected_number_of_messages " ,
207
+ "force,diff,local_file_changed ,expect_prompt,user_validation ,expect_update" ,
181
208
[
182
- (True , True , True , False , False , True , 3 ), # Force is on, we have a diff, prompt should not be displayed: we expect update.
183
- (
184
- True ,
185
- False ,
186
- True ,
187
- False ,
188
- False ,
189
- True ,
190
- 3 ,
191
- ), # Force is on, no diff, should_update_resource == true, prompt should not be displayed, we expect update.
192
- (
193
- True ,
194
- False ,
195
- False ,
196
- False ,
197
- False ,
198
- False ,
199
- 1 ,
200
- ), # Force is on, no diff, should_update_resource == false, prompt should not be displayed, we don't expect update. This scenario should not exists in current implementation as force always trigger update.
201
- (
202
- False ,
203
- True ,
204
- True ,
205
- True ,
206
- True ,
207
- True ,
208
- 3 ,
209
- ), # Force is off, we have diff, prompt should be displayed, user validate diff: we expected update.
210
- (
211
- False ,
212
- False ,
213
- True ,
214
- False ,
215
- False ,
216
- True ,
217
- 3 ,
218
- ), # Force is off, no diff, should_update_resource == true (in case of file change), prompt should not be displayed, we expect update.
219
- (
220
- False ,
221
- True ,
222
- True ,
223
- True ,
224
- False ,
225
- False ,
226
- 1 ,
227
- ), # Force is off, we have a diff but the user does not validate it: we don't expect update.
228
- (
229
- False ,
230
- False ,
231
- False ,
232
- False ,
233
- False ,
234
- False ,
235
- 1 ,
236
- ), # Force is off, we have a no diff, should_update_resource == false: we don't expect update.
209
+ pytest .param (True , True , True , False , False , True , id = "Force, diff, local file change -> no prompt, no validation, expect update." ),
210
+ pytest .param (
211
+ True , True , False , False , False , True , id = "Force, diff, no local file change -> no prompt, no validation, expect update."
212
+ ),
213
+ pytest .param (
214
+ True , False , False , False , False , True , id = "Force, no diff, no local file change -> no prompt, no validation, expect update."
215
+ ),
216
+ pytest .param (
217
+ True , False , True , False , False , True , id = "Force, no diff, local file change -> no prompt, no validation, expect update."
218
+ ),
219
+ pytest .param (
220
+ False , True , True , True , True , True , id = "No force, diff, local file change -> expect prompt, validation, expect update."
221
+ ),
222
+ pytest .param (
223
+ False , True , True , True , False , False , id = "No force, diff, local file change -> expect prompt, no validation, no update."
224
+ ),
225
+ pytest .param (
226
+ False , True , False , True , True , True , id = "No force, diff, no local file change -> expect prompt, validation, expect update."
227
+ ),
228
+ pytest .param (
229
+ False , True , False , True , False , False , id = "No force, diff, no local file change -> expect prompt, no validation, no update."
230
+ ),
231
+ pytest .param (
232
+ False , False , True , False , False , True , id = "No force, no diff, local file change -> no prompt, no validation, expect update."
233
+ ),
234
+ pytest .param (
235
+ False , False , False , False , False , False , id = "No force, no diff, no local file change -> no prompt, no validation, no update."
236
+ ),
237
237
],
238
238
)
239
- def test_update_resource (
240
- patch_click , mocker , force , diff , should_update_resource , user_validate_diff , expect_prompt , expect_update , expected_number_of_messages
241
- ):
239
+ def test_update_resource (patch_click , mocker , force , diff , local_file_changed , expect_prompt , user_validation , expect_update ):
242
240
mock_updated_resource = mocker .Mock ()
243
241
mock_state = mocker .Mock ()
244
242
mock_resource = mocker .Mock (
245
243
get_diff_with_remote_resource = mocker .Mock (return_value = diff ),
246
244
resource_name = "my_resource" ,
245
+ local_file_changed = local_file_changed ,
247
246
update = mocker .Mock (return_value = (mock_updated_resource , mock_state )),
248
247
)
249
- update_reason = "foo"
250
- mocker .patch .object (commands , "should_update_resource" , mocker .Mock (return_value = (should_update_resource , update_reason )))
251
- mocker .patch .object (commands , "prompt_for_diff_validation" , mocker .Mock (return_value = user_validate_diff ))
248
+ mocker .patch .object (commands , "prompt_for_diff_validation" , mocker .Mock (return_value = user_validation ))
252
249
253
250
output_messages = commands .update_resource (mock_resource , force )
251
+ commands .click .echo .assert_called_once ()
252
+
254
253
if expect_prompt :
255
254
commands .prompt_for_diff_validation .assert_called_once_with ("my_resource" , diff )
256
255
else :
@@ -259,11 +258,9 @@ def test_update_resource(
259
258
mock_resource .update .assert_called_once ()
260
259
else :
261
260
mock_resource .update .assert_not_called ()
262
- assert output_messages [0 ] == commands .should_update_resource .return_value [1 ] == update_reason
263
- assert len (output_messages ) == expected_number_of_messages
264
- if expected_number_of_messages == 3 :
261
+
262
+ if expect_update :
265
263
assert output_messages == [
266
- commands .should_update_resource .return_value [1 ],
267
264
commands .click .style .return_value ,
268
265
commands .click .style .return_value ,
269
266
]
@@ -273,6 +270,8 @@ def test_update_resource(
273
270
mocker .call (f"💾 - New state for { mock_updated_resource .name } stored at { mock_state .path } ." , fg = "yellow" ),
274
271
]
275
272
)
273
+ else :
274
+ assert output_messages == []
276
275
277
276
278
277
def test_find_local_configuration_files (mocker ):
0 commit comments