7
7
from code42cli .main import cli
8
8
9
9
10
+ _NAMESPACE = "code42cli.cmds.users"
11
+
10
12
TEST_ROLE_RETURN_DATA = {
11
13
"data" : [{"roleName" : "Customer Cloud Admin" , "roleId" : "1234543" }]
12
14
}
@@ -50,6 +52,11 @@ def get_all_users_generator():
50
52
yield TEST_USERS_RESPONSE
51
53
52
54
55
+ @pytest .fixture
56
+ def update_user_response (mocker ):
57
+ return _create_py42_response (mocker , "" )
58
+
59
+
53
60
@pytest .fixture
54
61
def get_available_roles_response (mocker ):
55
62
return _create_py42_response (mocker , json .dumps (TEST_ROLE_RETURN_DATA ))
@@ -75,6 +82,11 @@ def get_available_roles_success(cli_state, get_available_roles_response):
75
82
cli_state .sdk .users .get_available_roles .return_value = get_available_roles_response
76
83
77
84
85
+ @pytest .fixture
86
+ def update_user_success (cli_state , update_user_response ):
87
+ cli_state .sdk .users .update_user .return_value = update_user_response
88
+
89
+
78
90
def test_list_when_non_table_format_outputs_expected_columns (
79
91
runner , cli_state , get_all_users_success
80
92
):
@@ -263,3 +275,116 @@ def test_remove_user_role_raises_error_when_username_does_not_exist(
263
275
result = runner .invoke (cli , command , obj = cli_state )
264
276
assert result .exit_code == 1
265
277
assert "User '[email protected] ' does not exist." in result .
output
278
+
279
+
280
+ def test_update_user_calls_update_user_with_correct_parameters_when_only_some_are_passed (
281
+ runner , cli_state , update_user_success
282
+ ):
283
+ command = ["users" , "update" , "--user-id" , "12345" , "--email" , "test_email" ]
284
+ runner .invoke (cli , command , obj = cli_state )
285
+ cli_state .sdk .users .update_user .assert_called_once_with (
286
+ "12345" ,
287
+ username = None ,
288
+ email = "test_email" ,
289
+ password = None ,
290
+ first_name = None ,
291
+ last_name = None ,
292
+ notes = None ,
293
+ archive_size_quota_bytes = None ,
294
+ )
295
+
296
+
297
+ def test_update_user_calls_update_user_with_correct_parameters_when_all_are_passed (
298
+ runner , cli_state , update_user_success
299
+ ):
300
+ command = [
301
+ "users" ,
302
+ "update" ,
303
+ "--user-id" ,
304
+ "12345" ,
305
+ "--email" ,
306
+ "test_email" ,
307
+ "--username" ,
308
+ "test_username" ,
309
+ "--password" ,
310
+ "test_password" ,
311
+ "--first-name" ,
312
+ "test_fname" ,
313
+ "--last-name" ,
314
+ "test_lname" ,
315
+ "--notes" ,
316
+ "test notes" ,
317
+ "--archive-size-quota" ,
318
+ "123456" ,
319
+ ]
320
+ runner .invoke (cli , command , obj = cli_state )
321
+ cli_state .sdk .users .update_user .assert_called_once_with (
322
+ "12345" ,
323
+ username = "test_username" ,
324
+ email = "test_email" ,
325
+ password = "test_password" ,
326
+ first_name = "test_fname" ,
327
+ last_name = "test_lname" ,
328
+ notes = "test notes" ,
329
+ archive_size_quota_bytes = "123456" ,
330
+ )
331
+
332
+
333
+ def test_bulk_deactivate_uses_expected_arguments_when_only_some_are_passed (
334
+ runner , mocker , cli_state
335
+ ):
336
+ bulk_processor = mocker .patch (f"{ _NAMESPACE } .run_bulk_process" )
337
+ with runner .isolated_filesystem ():
338
+ with open ("test_bulk_update.csv" , "w" ) as csv :
339
+ csv .writelines (
340
+ [
341
+ "user_id,username,email,password,first_name,last_name,notes,archive_size_quota\n " ,
342
+ "12345,,test_email,,,,,\n " ,
343
+ ]
344
+ )
345
+ runner .invoke (
346
+ cli , ["users" , "bulk" , "update" , "test_bulk_update.csv" ], obj = cli_state
347
+ )
348
+ assert bulk_processor .call_args [0 ][1 ] == [
349
+ {
350
+ "user_id" : "12345" ,
351
+ "username" : "" ,
352
+ "email" : "test_email" ,
353
+ "password" : "" ,
354
+ "first_name" : "" ,
355
+ "last_name" : "" ,
356
+ "notes" : "" ,
357
+ "archive_size_quota" : "" ,
358
+ "updated" : "False" ,
359
+ }
360
+ ]
361
+
362
+
363
+ def test_bulk_deactivate_uses_expected_arguments_when_all_are_passed (
364
+ runner , mocker , cli_state
365
+ ):
366
+ bulk_processor = mocker .patch (f"{ _NAMESPACE } .run_bulk_process" )
367
+ with runner .isolated_filesystem ():
368
+ with open ("test_bulk_update.csv" , "w" ) as csv :
369
+ csv .writelines (
370
+ [
371
+ "user_id,username,email,password,first_name,last_name,notes,archive_size_quota\n " ,
372
+ "12345,test_username,test_email,test_pword,test_fname,test_lname,test notes,4321\n " ,
373
+ ]
374
+ )
375
+ runner .invoke (
376
+ cli , ["users" , "bulk" , "update" , "test_bulk_update.csv" ], obj = cli_state
377
+ )
378
+ assert bulk_processor .call_args [0 ][1 ] == [
379
+ {
380
+ "user_id" : "12345" ,
381
+ "username" : "test_username" ,
382
+ "email" : "test_email" ,
383
+ "password" : "test_pword" ,
384
+ "first_name" : "test_fname" ,
385
+ "last_name" : "test_lname" ,
386
+ "notes" : "test notes" ,
387
+ "archive_size_quota" : "4321" ,
388
+ "updated" : "False" ,
389
+ }
390
+ ]
0 commit comments