@@ -157,6 +157,8 @@ def tearDown(self):
157
157
158
158
deinit_froster (self )
159
159
160
+ # HELPERS
161
+
160
162
def helper_set_default_cli_arguments (self ):
161
163
'''- Set default arguments.'''
162
164
@@ -167,10 +169,10 @@ def helper_set_default_cli_arguments(self):
167
169
@patch ('inquirer.prompt' , side_effect = [{'aws_dir' : AWS_DEFAULT_PATH }, {'shared_dir' : SHARED_DIR }])
168
170
@patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION , '+ Create new bucket' , S3_STORAGE_CLASS ])
169
171
@patch ('inquirer.confirm' , side_effect = [False , False ])
170
- def test_subcmd_config (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
171
- '''- Set full configuration'''
172
+ def helper_run_subcmd_config (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
173
+ '''- Helper that sets full configuration'''
172
174
173
- # Check that nothing is set
175
+ # Check that nothing is set yet
174
176
self .assertFalse (self .cfg .user_init )
175
177
self .assertFalse (self .cfg .aws_init )
176
178
self .assertFalse (self .cfg .nih_init )
@@ -182,6 +184,21 @@ def test_subcmd_config(self, mock_print, mock_text, mock_prompt, mock_list, mock
182
184
# Mock the "froster config" command
183
185
self .assertTrue (self .cmd .subcmd_config (cfg = self .cfg , aws = self .aws ))
184
186
187
+ @patch ('inquirer.text' , side_effect = [NAME_2 , EMAIL_2 , AWS_PROFILE_2 , AWS_ACCESS_KEY_ID , AWS_SECRET , S3_BUCKET_NAME_2 , S3_ARCHIVE_DIR_2 ])
188
+ @patch ('inquirer.prompt' , side_effect = [{'aws_dir' : AWS_DEFAULT_PATH }, {'shared_dir' : SHARED_DIR }])
189
+ @patch ('inquirer.list_input' , side_effect = ['+ Create new profile' , AWS_REGION_2 , '+ Create new bucket' , S3_STORAGE_CLASS_2 ])
190
+ @patch ('inquirer.confirm' , side_effect = [True , False , False ])
191
+ def helper_run_subcmd_config_overwrite (self , mock_print , mock_text , mock_prompt , mock_list , mock_confirm ):
192
+ '''- Helper that sets full configuration'''
193
+
194
+ # Mock the CLI default arguments
195
+ self .helper_set_default_cli_arguments ()
196
+
197
+ # Mock the "froster config" command
198
+ self .assertTrue (self .cmd .subcmd_config (cfg = self .cfg , aws = self .aws ))
199
+
200
+ def helper_check_subcmd_config (self ):
201
+
185
202
# Check that everything is set
186
203
self .assertTrue (self .cfg .user_init )
187
204
self .assertTrue (self .cfg .aws_init )
@@ -222,7 +239,7 @@ def test_subcmd_config(self, mock_print, mock_text, mock_prompt, mock_list, mock
222
239
# NIH config checks
223
240
check_ini_file (self , self .cfg .config_file ,
224
241
NIH_SECTION , 'is_nih' , 'False' )
225
-
242
+
226
243
# S3 config checks
227
244
check_ini_file (self , self .cfg .config_file ,
228
245
S3_SECTION , 'bucket_name' , S3_BUCKET_NAME )
@@ -237,6 +254,83 @@ def test_subcmd_config(self, mock_print, mock_text, mock_prompt, mock_list, mock
237
254
s3_buckets = self .aws .get_buckets ()
238
255
self .assertIn (S3_BUCKET_NAME , s3_buckets )
239
256
257
+ def helper_check_subcmd_config_overwrite (self ):
258
+
259
+ # Check that everything is set
260
+ self .assertTrue (self .cfg .user_init )
261
+ self .assertTrue (self .cfg .aws_init )
262
+ self .assertTrue (self .cfg .nih_init )
263
+ self .assertTrue (self .cfg .s3_init )
264
+
265
+ # USER config checks
266
+ check_ini_file (self , self .cfg .config_file ,
267
+ USER_SECTION , 'name' , NAME_2 )
268
+ check_ini_file (self , self .cfg .config_file ,
269
+ USER_SECTION , 'email' , EMAIL_2 )
270
+
271
+ # AWS config checks
272
+ check_ini_file (self , self .cfg .config_file ,
273
+ AWS_SECTION , 'aws_profile' , AWS_PROFILE_2 )
274
+
275
+ check_ini_file (self , self .cfg .config_file ,
276
+ AWS_SECTION , 'aws_region' , AWS_REGION_2 )
277
+
278
+ check_ini_file (self , self .cfg .aws_credentials_file , AWS_PROFILE_2 ,
279
+ 'aws_access_key_id' , AWS_ACCESS_KEY_ID )
280
+
281
+ check_ini_file (self , self .cfg .aws_credentials_file ,
282
+ AWS_PROFILE_2 , 'aws_secret_access_key' , AWS_SECRET )
283
+
284
+ check_ini_file (self , self .cfg .aws_config_file ,
285
+ AWS_PROFILE_2 , 'region' , AWS_REGION_2 )
286
+
287
+ check_ini_file (self , self .cfg .aws_config_file ,
288
+ AWS_PROFILE_2 , 'output' , 'json' )
289
+
290
+ self .assertTrue (self .aws .check_credentials ())
291
+
292
+ # SHARED config checks
293
+ check_ini_file (self , self .cfg .config_file ,
294
+ SHARED_SECTION , 'is_shared' , 'False' )
295
+
296
+ # NIH config checks
297
+ check_ini_file (self , self .cfg .config_file ,
298
+ NIH_SECTION , 'is_nih' , 'False' )
299
+
300
+ # S3 config checks
301
+ check_ini_file (self , self .cfg .config_file ,
302
+ S3_SECTION , 'bucket_name' , S3_BUCKET_NAME_2 )
303
+
304
+ check_ini_file (self , self .cfg .config_file ,
305
+ S3_SECTION , 'archive_dir' , S3_ARCHIVE_DIR_2 )
306
+
307
+ check_ini_file (self , self .cfg .config_file ,
308
+ S3_SECTION , 'storage_class' , S3_STORAGE_CLASS_2 )
309
+
310
+ # Check the bucket was created
311
+ s3_buckets = self .aws .get_buckets ()
312
+ self .assertIn (S3_BUCKET_NAME_2 , s3_buckets )
313
+
314
+ # TESTS
315
+
316
+ def test_subcmd_config (self , mock_print ):
317
+ '''- Set full configuration'''
318
+
319
+ self .helper_run_subcmd_config (None )
320
+
321
+ self .helper_check_subcmd_config ()
322
+
323
+ def test_subcmd_config_overwrite (self , mock_print ,):
324
+ '''- Overwirte current configuration'''
325
+
326
+ self .helper_run_subcmd_config (None )
327
+
328
+ self .helper_check_subcmd_config ()
329
+
330
+ self .helper_run_subcmd_config_overwrite (None )
331
+
332
+ self .helper_check_subcmd_config_overwrite ()
333
+
240
334
241
335
@patch ('builtins.print' )
242
336
class TestConfigUser (unittest .TestCase ):
0 commit comments