@@ -254,7 +254,7 @@ def mock_backup_set(mocker):
254254
255255
256256@pytest .fixture
257- def deactivate_response (mocker ):
257+ def empty_successful_response (mocker ):
258258 return _create_py42_response (mocker , "" )
259259
260260
@@ -303,15 +303,25 @@ def archives_list_success(cli_state):
303303
304304
305305@pytest .fixture
306- def deactivate_device_success (cli_state , deactivate_response ):
307- cli_state .sdk .devices .deactivate .return_value = deactivate_response
306+ def deactivate_device_success (cli_state , empty_successful_response ):
307+ cli_state .sdk .devices .deactivate .return_value = empty_successful_response
308+
309+
310+ @pytest .fixture
311+ def reactivate_device_success (cli_state , empty_successful_response ):
312+ cli_state .sdk .devices .reactivate .return_value = empty_successful_response
308313
309314
310315@pytest .fixture
311316def deactivate_device_not_found_failure (cli_state ):
312317 cli_state .sdk .devices .deactivate .side_effect = Py42NotFoundError (HTTPError ())
313318
314319
320+ @pytest .fixture
321+ def reactivate_device_not_found_failure (cli_state ):
322+ cli_state .sdk .devices .reactivate .side_effect = Py42NotFoundError (HTTPError ())
323+
324+
315325@pytest .fixture
316326def deactivate_device_in_legal_hold_failure (cli_state ):
317327 cli_state .sdk .devices .deactivate .side_effect = Py42BadRequestError (HTTPError ())
@@ -322,6 +332,11 @@ def deactivate_device_not_allowed_failure(cli_state):
322332 cli_state .sdk .devices .deactivate .side_effect = Py42ForbiddenError (HTTPError ())
323333
324334
335+ @pytest .fixture
336+ def reactivate_device_not_allowed_failure (cli_state ):
337+ cli_state .sdk .devices .reactivate .side_effect = Py42ForbiddenError (HTTPError ())
338+
339+
325340@pytest .fixture
326341def backupusage_success (cli_state , backupusage_response ):
327342 cli_state .sdk .devices .get_by_guid .return_value = backupusage_response
@@ -440,6 +455,33 @@ def test_deactivate_fails_if_device_deactivation_forbidden(
440455 assert "Unable to deactivate {}." .format (TEST_DEVICE_GUID ) in result .output
441456
442457
458+ def test_reactivate_reactivates_device (
459+ runner , cli_state , deactivate_device_success , get_device_by_guid_success
460+ ):
461+ runner .invoke (cli , ["devices" , "reactivate" , TEST_DEVICE_GUID ], obj = cli_state )
462+ cli_state .sdk .devices .reactivate .assert_called_once_with (TEST_DEVICE_ID )
463+
464+
465+ def test_reactivate_fails_if_device_does_not_exist (
466+ runner , cli_state , reactivate_device_not_found_failure
467+ ):
468+ result = runner .invoke (
469+ cli , ["devices" , "reactivate" , TEST_DEVICE_GUID ], obj = cli_state
470+ )
471+ assert result .exit_code == 1
472+ assert f"The device { TEST_DEVICE_GUID } was not found." in result .output
473+
474+
475+ def test_reactivate_fails_if_device_reactivation_forbidden (
476+ runner , cli_state , reactivate_device_not_allowed_failure
477+ ):
478+ result = runner .invoke (
479+ cli , ["devices" , "reactivate" , TEST_DEVICE_GUID ], obj = cli_state
480+ )
481+ assert result .exit_code == 1
482+ assert f"Unable to reactivate { TEST_DEVICE_GUID } ." in result .output
483+
484+
443485def test_show_prints_device_info (runner , cli_state , backupusage_success ):
444486 result = runner .invoke (cli , ["devices" , "show" , TEST_DEVICE_GUID ], obj = cli_state )
445487 assert "SNWINTEST1" in result .output
@@ -581,7 +623,7 @@ def test_add_backup_set_settings_to_dataframe_returns_one_line_per_backup_set(
581623
582624
583625def test_bulk_deactivate_uses_expected_arguments (runner , mocker , cli_state ):
584- bulk_processor = mocker .patch ("{ }.run_bulk_process". format ( _NAMESPACE ) )
626+ bulk_processor = mocker .patch (f" { _NAMESPACE } .run_bulk_process" )
585627 with runner .isolated_filesystem ():
586628 with open ("test_bulk_deactivate.csv" , "w" ) as csv :
587629 csv .writelines (["guid,username\n " , "test,value\n " ])
@@ -598,3 +640,16 @@ def test_bulk_deactivate_uses_expected_arguments(runner, mocker, cli_state):
598640 "purge_date" : None ,
599641 }
600642 ]
643+
644+
645+ def test_bulk_reactivate_uses_expected_arguments (runner , mocker , cli_state ):
646+ bulk_processor = mocker .patch (f"{ _NAMESPACE } .run_bulk_process" )
647+ with runner .isolated_filesystem ():
648+ with open ("test_bulk_reactivate.csv" , "w" ) as csv :
649+ csv .writelines (["guid,username\n " , "test,value\n " ])
650+ runner .invoke (
651+ cli ,
652+ ["devices" , "bulk" , "reactivate" , "test_bulk_reactivate.csv" ],
653+ obj = cli_state ,
654+ )
655+ assert bulk_processor .call_args [0 ][1 ] == [{"guid" : "test" , "reactivated" : False }]
0 commit comments