def test_remove_devices_success_withoutrange(self, mock_wok_log, mock_run_command): """ unit test to validate _remove_devices() success scenario in which the device list doesn't include range of devices mock_wok_log: mock of wok_log of model.cioignore mock_run_command: mock of wok.utils.run_command imported in model.cioignore """ devices = ['device1', 'device2'] mock_run_command.return_value = ['', '', 0] def cb(msg, status=None): pass _remove_devices(cb, devices) calls_run_command = [([CIO_IGNORE, '-r', 'device1'], ), ([CIO_IGNORE, '-r', 'device2'], )] for i in range(0, 2): x, y = mock_run_command.call_args_list[i] assert x == calls_run_command[i] assert mock_run_command.call_count == 2 self.assertTrue(mock_wok_log.info.called, msg='Expected call to mock_wok_log.info().' ' Not called')
def test_remove_devices_some_invalid_ids(self, mock_wok_log, mock_run_command): """ unit test to validate _remove_devices() when list of devices include invalid devices mock_wok_log: mock of wok_log of model.cioignore mock_run_command: mock of wok.utils.run_command imported in model.cioignore _remove_devices() should remove only the valid devices from ignore list and should throw operation failed exception and task fails with list of invalid devices """ devices = [ 'device1', 'invalidé', ' ', ] mock_run_command.side_effect = iter([['', '', 0], ['', 'dummy_error', 1]]) def cb(msg, status=None): pass _remove_devices(cb, devices) calls_run_command = [([CIO_IGNORE, '-r', 'device1'], ), ([CIO_IGNORE, '-r', 'invalidé'], )] for i in range(0, 2): x, y = mock_run_command.call_args_list[i] assert x == calls_run_command[i] assert mock_run_command.call_count == 2 self.assertTrue(mock_wok_log.error.called, msg='Expected call to mock_wok_log.info().' ' Not called')
def test_remove_devices_success_withoutrange(self, mock_wok_log, mock_run_command): """ unit test to validate _remove_devices() success scenario in which the device list doesn't include range of devices mock_wok_log: mock of wok_log of model.cioignore mock_run_command: mock of wok.utils.run_command imported in model.cioignore """ devices = ['device1', 'device2'] mock_run_command.return_value = ['', '', 0] def cb(msg, status=None): pass _remove_devices(cb, devices) calls_run_command = [([CIO_IGNORE, '-r', 'device1'],), ([CIO_IGNORE, '-r', 'device2'],)] for i in range(0, 2): x, y = mock_run_command.call_args_list[i] assert x == calls_run_command[i] assert mock_run_command.call_count == 2 self.assertTrue(mock_wok_log.info.called, msg='Expected call to mock_wok_log.info().' ' Not called')
def test_remove_devices_success_withrange(self, mock_wok_log, mock_run_command): """ unit test to validate _remove_devices() success scenario in which the device list includes range of devices list includes combination of integer and string ids mock_wok_log: mock of wok_log of model.cioignore mock_run_command: mock of wok.utils.run_command imported in model.cioignore """ devices = ["dev1", "dev2 - dev20", 25, "dev26"] mock_run_command.return_value = ["", "", 0] def cb(msg, status=None): pass _remove_devices(cb, devices) calls_run_command = [ ([CIO_IGNORE, "-r", "dev1"],), ([CIO_IGNORE, "-r", "dev2-dev20"],), ([CIO_IGNORE, "-r", "25"],), ([CIO_IGNORE, "-r", "dev26"],), ] for i in range(0, 2): x, y = mock_run_command.call_args_list[i] assert x == calls_run_command[i] assert mock_run_command.call_count == 4 self.assertTrue(mock_wok_log.info.called, msg="Expected call to mock_wok_log.info()." " Not called")
def test_remove_devices_some_invalid_ids(self, mock_wok_log, mock_run_command): """ unit test to validate _remove_devices() when list of devices include invalid devices mock_wok_log: mock of wok_log of model.cioignore mock_run_command: mock of wok.utils.run_command imported in model.cioignore _remove_devices() should remove only the valid devices from ignore list and should throw operation failed exception and task fails with list of invalid devices """ devices = ['device1', 'invalidé', ' ', ] mock_run_command.side_effect = iter([['', '', 0], ['', 'dummy_error', 1]]) def cb(msg, status=None): pass _remove_devices(cb, devices) calls_run_command = [([CIO_IGNORE, '-r', 'device1'],), ([CIO_IGNORE, '-r', 'invalidé'],)] for i in range(0, 2): x, y = mock_run_command.call_args_list[i] assert x == calls_run_command[i] assert mock_run_command.call_count == 2 self.assertTrue(mock_wok_log.error.called, msg='Expected call to mock_wok_log.info().' ' Not called')