def test_input_cancel_with_validator(self, mock_util): mock_util().input.side_effect = [(display_util.CANCEL, "")] code, unused_raw = ops.validated_input(self.__validator, "message", force_interactive=True) self.assertEqual(code, display_util.CANCEL)
def test_input_validation_with_default(self, mock_util): mock_util().input.side_effect = [(display_util.OK, self.valid_input)] returned = ops.validated_input(self.__validator, "msg", default="other") self.assertEqual(returned, (display_util.OK, self.valid_input))
def test_input_blank_with_validator(self, mock_util): mock_util().input.side_effect = [(display_util.OK, ""), (display_util.OK, ""), (display_util.OK, ""), (display_util.OK, self.valid_input)] returned = ops.validated_input(self.__validator, "message", force_interactive=True) self.assertEqual(ValidatorTests.__ERROR, mock_util().notification.call_args[0][0]) self.assertEqual(returned, (display_util.OK, self.valid_input))
def _prompt_for_data(label): """ Prompt the user for a piece of information. :param str label: The user-friendly label for this piece of information. :returns: The user's response (guaranteed non-empty). :rtype: str """ def __validator(i): # pylint: disable=unused-private-member if not i: raise errors.PluginError( 'Please enter your {0}.'.format(label)) code, response = ops.validated_input(__validator, 'Input your {0}'.format(label), force_interactive=True) if code == display_util.OK: return response raise errors.PluginError('{0} required to proceed.'.format(label))
def _prompt_for_data(label): """ Prompt the user for a piece of information. :param str label: The user-friendly label for this piece of information. :returns: The user's response (guaranteed non-empty). :rtype: str """ def __validator(i): if not i: raise errors.PluginError('Please enter your {0}.'.format(label)) code, response = ops.validated_input( __validator, 'Input your {0}'.format(label), force_interactive=True) if code == display_util.OK: return response else: raise errors.PluginError('{0} required to proceed.'.format(label))