Пример #1
0
 def validate_email(self, value):
     if self.partial_email:
         return
     try:
         validate_email_address(value)
     except InvalidEmailError as e:
         raise ValidationError(str(e))
Пример #2
0
    def __call__(self, form, field):

        if field.data == '':
            return

        try:
            validate_email_address(field.data)
        except InvalidEmailError:
            raise ValidationError(self.message)
Пример #3
0
    def __post_init__(self):
        # email address is mandatory for us
        assert len(self.email_address), "email can NOT be blank"
        validate_email_address(self.email_address)

        # HTML sanitize all fields that are string based
        for f in fields(self):
            try:
                if issubclass(f.type, str):
                    setattr(self, f.name, str(escape(getattr(self, f.name))))
            except TypeError:
                pass
Пример #4
0
def test_validate_government_domain_data():

    for domain in AgreementInfo.domains.keys():

        validate_email_address('test@{}'.format(domain))

        agreement_info = AgreementInfo(domain)

        assert agreement_info.crown_status in {True, False, None}

        assert (agreement_info.owner is None) or (isinstance(
            agreement_info.owner, str))

        assert agreement_info.agreement_signed in {True, False, None}
Пример #5
0
    def from_string(cls, service_id, recipient_type, recipient):
        instance = cls(service_id=service_id, recipient_type=recipient_type)

        try:
            if recipient_type == MOBILE_TYPE:
                validate_phone_number(recipient)
                instance.recipient = recipient
            elif recipient_type == EMAIL_TYPE:
                validate_email_address(recipient)
                instance.recipient = recipient
            else:
                raise ValueError('Invalid recipient type')
        except InvalidPhoneError:
            raise ValueError('Invalid whitelist: "{}"'.format(recipient))
        except InvalidEmailError:
            raise ValueError('Invalid whitelist: "{}"'.format(recipient))
        else:
            return instance
Пример #6
0
def test_validate_email_domain_data():

    for domain in GovernmentEmailDomain.domains.keys():
        validate_email_address('test@{}'.format(domain))
Пример #7
0
def validate_schema_email_address(instance):
    if isinstance(instance, str):
        validate_email_address(instance)
    return True
Пример #8
0
 def validate_to(self, value):
     try:
         validate_email_address(value)
     except InvalidEmailError as e:
         raise ValidationError(str(e))
Пример #9
0
def test_validate_email_address_raises_for_invalid(email_address):
    with pytest.raises(InvalidEmailError) as e:
        validate_email_address(email_address)
    assert str(e.value) == 'Not a valid email address'
Пример #10
0
 def validate_schema_email_address(instance):
     if instance is not None:
         validate_email_address(instance)
     return True
Пример #11
0
def test_validate_email_address_accepts_valid(email_address):
    try:
        assert validate_email_address(email_address) == email_address
    except InvalidEmailError:
        pytest.fail('Unexpected InvalidEmailError')
Пример #12
0
def test_validate_email_address_strips_whitespace(email):
    assert validate_email_address(email) == '*****@*****.**'
Пример #13
0
 def __call__(self, form, field):
     try:
         validate_email_address(field.data)
     except InvalidEmailError:
         raise ValidationError(self.message)
     return super().__call__(form, field)
Пример #14
0
 def validate_email(self, value):
     try:
         validate_email_address(value)
     except InvalidEmailError as e:
         raise ValidationError(e.message)
def test_validate_email_address_accepts_valid(email_address):
    try:
        assert validate_email_address(email_address) == email_address
    except InvalidEmailError:
        pytest.fail('Unexpected InvalidEmailError')
def test_validate_email_address_strips_whitespace():
    assert validate_email_address('[email protected] ') == '*****@*****.**'
def test_validate_email_address_raises_for_invalid(email_address):
    with pytest.raises(InvalidEmailError):
        validate_email_address(email_address)