def validate_send_message_input(input_dict): """ Validates the input supplied for the POST call on the message resource. Args: input_dict - JSON input in dictionary form Throws: InvalidInputException when input is malformed or doesn't match schema """ ## Validate against JSON schema try: validate(input_dict, send_input_schema_dict) except ValidationError as e: raise InvalidInputException(e.message) ## Validate email addresses invalid_emails = [] # Validate from from_email = input_dict.get('from') if (not MailerUtils.is_email_valid(from_email)): invalid_emails.append(from_email) # Validate to for to_email in input_dict.get('to'): if (not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) # Validate cc for to_email in input_dict.get('cc', []): if (not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) # Validate bcc for to_email in input_dict.get('bcc', []): if (not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) if (len(invalid_emails) != 0): payload = {"invalid_emails": invalid_emails} raise InvalidInputException(message="Input contains invalid email(s)", payload=payload)
def validate_send_message_input(input_dict): """ Validates the input supplied for the POST call on the message resource. Args: input_dict - JSON input in dictionary form Throws: InvalidInputException when input is malformed or doesn't match schema """ ## Validate against JSON schema try: validate(input_dict, send_input_schema_dict) except ValidationError as e: raise InvalidInputException(e.message) ## Validate email addresses invalid_emails = [] # Validate from from_email = input_dict.get('from') if(not MailerUtils.is_email_valid(from_email)): invalid_emails.append(from_email) # Validate to for to_email in input_dict.get('to'): if(not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) # Validate cc for to_email in input_dict.get('cc', []): if(not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) # Validate bcc for to_email in input_dict.get('bcc',[]): if(not MailerUtils.is_email_valid(to_email)): invalid_emails.append(to_email) if(len(invalid_emails)!=0): payload = {"invalid_emails":invalid_emails} raise InvalidInputException(message = "Input contains invalid email(s)", payload = payload)
def validate_get_status_input(input_dict): """ Validates the input supplied for the POST call on the info resource. Args: input_dict (dict) - JSON input in dictionary form Throws: InvalidInputException when input is malformed or doesn't match schema for this call. """ # Validate against JSON schema try: validate(input_dict, info_input_schema_dict) except ValidationError as e: raise InvalidInputException(e.message) # Validate email address email = input_dict.get('email') if(not MailerUtils.is_email_valid(email)): raise InvalidInputException(message = "Input contains invalid email: "+email)
def validate_get_status_input(input_dict): """ Validates the input supplied for the POST call on the info resource. Args: input_dict (dict) - JSON input in dictionary form Throws: InvalidInputException when input is malformed or doesn't match schema for this call. """ # Validate against JSON schema try: validate(input_dict, info_input_schema_dict) except ValidationError as e: raise InvalidInputException(e.message) # Validate email address email = input_dict.get('email') if (not MailerUtils.is_email_valid(email)): raise InvalidInputException(message="Input contains invalid email: " + email)
def test_is_email_valid(self): assert MailerUtils.is_email_valid("Amit Ruparel <*****@*****.**>") == True assert MailerUtils.is_email_valid("*****@*****.**") == True assert MailerUtils.is_email_valid("blah") == False assert MailerUtils.is_email_valid("") == False assert MailerUtils.is_email_valid(None) == False