def test_validator(self):
     self.assertRaises(
         ValidationError,
         validators.validate_disposable_email,
         self.disposable_email,
     )
     validators.validate_disposable_email(self.not_a_disposable_email)
    def test_validator_messages(self):
        with self.assertRaisesMessage(ValidationError, 'Blocked email provider.'):
            validators.validate_disposable_email(self.disposable_email)

        with self.settings(BDEA_MESSAGE='Test message'):
            # As the `BDEA_MESSAGE` gets calculated at run time we need to reload the module that
            #  defines the message.
            six.moves.reload_module(validators)
            with self.assertRaisesMessage(ValidationError, 'Test message'):
                validators.validate_disposable_email(self.disposable_email)

        # We need to reload the module again to set the default functionality back to normal.
        six.moves.reload_module(validators)
    def test_validator_messages(self):
        with self.assertRaisesMessage(ValidationError, 'Blocked email provider.'):
            validators.validate_disposable_email(self.disposable_email)

        with self.settings(BDEA_MESSAGE='Test message'):
            # As the `BDEA_MESSAGE` gets calculated at run time we need to reload the module that
            #  defines the message.
            reload(validators)
            with self.assertRaisesMessage(ValidationError, 'Test message'):
                validators.validate_disposable_email(self.disposable_email)

        # We need to reload the module again to set the default functionality back to normal.
        reload(validators)
Ejemplo n.º 4
0
def validate_email(value):
    """Validate a single email."""
    if not value:
        return False
    # Check the regex, using the validate_email from django.
    try:
        django_validate_email(value)
    except ValidationError:
        return False
    else:
        # Check with the disposable list.
        try:
            validate_disposable_email(value)
        except ValidationError:
            return False
        else:
            return True
 def test_validator(self):
     self.assertRaises(ValidationError, validators.validate_disposable_email, self.disposable_email)
     validators.validate_disposable_email(self.not_a_disposable_email)