def validateinput()

in functions/source/new_account_handler.py [0:0]


def validateinput(row):
    '''Return validation status and error list if found any'''

    error_list = list()
    validation = 'VALID'
    emailexpression = r'[^\s@]+@[^\s@]+\.[^\s@]+'
    fields = ['AccountName', 'AccountEmail', 'SSOUserEmail',
              'OrgUnit', 'SSOUserFirstName', 'SSOUserLastName']

    for field in fields:
        if row[field] == 'None':
            error_list.append(field + "is a required field.")

    if len(row['AccountName']) > 50:
        error_list.append("AccountName should be less than 50 characters., ")
    if len(row['AccountEmail']) < 7:
        error_list.append("AccountEmail should be more than 6 characters., ")
    if len(row['SSOUserEmail']) < 7:
        error_list.append("SSOUserEmail should be more than 6 characters., ")
    if re.match(emailexpression, row['AccountEmail']) is None:
        error_list.append("AccountEmail is not valid., ")
    if re.match(emailexpression, row['SSOUserEmail']) is None:
        error_list.append("SSOUserEmail is not valid., ")
    if not validate_org_unit(row['OrgUnit']):
        error_list.append("OrgUnit " + row['OrgUnit'] + " is not valid")
    if is_email_exists(row['AccountEmail']):
        error_list.append("Account email - " + row['AccountEmail']
                          + " in use by another account")

    if len(error_list) > 0:
        validation = 'INVALID'
        LOGGER.info('Validation status %s and error message %s ',
                    validation, error_list)

    return (validation, error_list)