示例#1
0
def set_username(username: Optional[str] = None,
                 prompt: Optional[str] = None) -> str:
    """Sets the username in the registry.

  Optionally prompts if there is no username supplied as a parameter.

  Args:
    username: Value to set as the username in registry.
    prompt: Custom string to append to username prompt.

  Returns:
    username: The determined username.

  Raises:
    Error: Failed to set username in registry.
  """
    if not username:
        username = interact.GetUsername(prompt)
    try:
        registry.set_value('Username', username, path=constants.REG_ROOT)
    except registry.Error as e:
        raise Error(e)

    return username
示例#2
0
 def testGetUsername(self, raw):
   raw.side_effect = iter(['invalid-name', '', '  ', 'username1'])
   self.assertEqual(interact.GetUsername(), 'username1')
示例#3
0
 def _SetUsername(self):
     self._username = interact.GetUsername()
示例#4
0
 def testGetUsernamePurpose(self, prompt):
     prompt.return_value = 'username1'
     self.assertEqual(interact.GetUsername('domain join'), 'username1')
     prompt.assert_called_with(
         'Please enter your username for domain join: ',
         validator='^[a-zA-Z0-9]+$')