Return the reason a username validation failed and add tests to verify we are sending the reason to client
This commit is contained in:
parent
a71c682abe
commit
0e54b0501c
3 changed files with 39 additions and 11 deletions
|
@ -61,8 +61,10 @@ class InvalidBuildTriggerException(DataModelException):
|
|||
def create_user(username, password, email, is_organization=False):
|
||||
if not validate_email(email):
|
||||
raise InvalidEmailAddressException('Invalid email address: %s' % email)
|
||||
if not validate_username(username):
|
||||
raise InvalidUsernameException('Invalid username: %s' % username)
|
||||
|
||||
(username_valid, username_issue) = validate_username(username)
|
||||
if not username_valid:
|
||||
raise InvalidUsernameException('Invalid username %s: %s' % (username, username_issue))
|
||||
|
||||
# We allow password none for the federated login case.
|
||||
if password is not None and not validate_password(password):
|
||||
|
@ -125,9 +127,10 @@ def create_organization(name, email, creating_user):
|
|||
|
||||
|
||||
def create_robot(robot_shortname, parent):
|
||||
if not validate_username(robot_shortname):
|
||||
raise InvalidRobotException('The name for the robot \'%s\' is invalid.' %
|
||||
robot_shortname)
|
||||
(username_valid, username_issue) = validate_username(robot_shortname)
|
||||
if not username_valid:
|
||||
raise InvalidRobotException('The name for the robot \'%s\' is invalid: %s' %
|
||||
(robot_shortname, username_issue))
|
||||
|
||||
username = format_robot_username(parent.username, robot_shortname)
|
||||
|
||||
|
@ -214,8 +217,9 @@ def convert_user_to_organization(user, admin_user):
|
|||
|
||||
|
||||
def create_team(name, org, team_role_name, description=''):
|
||||
if not validate_username(name):
|
||||
raise InvalidTeamException('Invalid team name: %s' % name)
|
||||
(username_valid, username_issue) = validate_username(name)
|
||||
if not username_valid:
|
||||
raise InvalidTeamException('Invalid team name %s: %s' % (name, username_issue))
|
||||
|
||||
if not org.organization:
|
||||
raise InvalidOrganizationException('User with name %s is not an org.' %
|
||||
|
|
Reference in a new issue