Example #1
0
 def test_is_pretty_from_raises_validation_error_on_bad_input(self):
     """
     Ensure invalid email addresses (e.g. "hello") raise
     ValidationError if given invalid inputs.
     """
     with self.assertRaises(ValidationError):
         self.assertTrue(is_pretty_from_address('hello'))
Example #2
0
    def post(self, request, *args, **kwargs):
        if not request.user.is_superuser:
            raise PermissionDenied

        from_address = settings.DEFAULT_FROM_EMAIL

        try:
            is_pretty = is_pretty_from_address(from_address)
        except ValidationError:
            return self.get(request, *args, **kwargs)

        message = render_to_string('djohno/email_body.txt',
                                   {'pretty_from': is_pretty})

        error = None

        try:
            send_mail('djohno email test',
                      message,
                      from_address, [
                          request.user.email,
                      ],
                      fail_silently=False)
        except SMTPException as e:
            error = e
        except socket.error as e:
            error = e

        return render(
            request, 'djohno/email_sent.html', {
                'email': request.user.email,
                'from_email': from_address,
                'error': error
            })
Example #3
0
    def post(self, request, *args, **kwargs):
        if not request.user.is_superuser:
            raise PermissionDenied

        from_address = settings.DEFAULT_FROM_EMAIL

        try:
            is_pretty = is_pretty_from_address(from_address)
        except ValidationError:
            return self.get(request, *args, **kwargs)

        message = render_to_string('djohno/email_body.txt',
                                   {'pretty_from': is_pretty})

        error = None

        try:
            send_mail('djohno email test',
                      message,
                      from_address,
                      [request.user.email, ],
                      fail_silently=False)
        except SMTPException as e:
            error = e
        except socket.error as e:
            error = e

        return render(request, 'djohno/email_sent.html',
                      {'email': request.user.email,
                       'from_email': from_address,
                       'error': error})
Example #4
0
    def get(self, request, *args, **kwargs):
        if not request.user.is_superuser:
            raise PermissionDenied

        from_address = settings.DEFAULT_FROM_EMAIL
        try:
            is_pretty = is_pretty_from_address(from_address)
        except ValidationError:
            return render(request, 'djohno/bad_email.html',
                          {'from_email': from_address})

        return render(request, 'djohno/email.html',
                      {'email': request.user.email,
                       'from_email': from_address,
                       'is_pretty': is_pretty})
Example #5
0
    def get(self, request, *args, **kwargs):
        if not request.user.is_superuser:
            raise PermissionDenied

        from_address = settings.DEFAULT_FROM_EMAIL
        try:
            is_pretty = is_pretty_from_address(from_address)
        except ValidationError:
            return render(request, 'djohno/bad_email.html',
                          {'from_email': from_address})

        return render(
            request, 'djohno/email.html', {
                'email': request.user.email,
                'from_email': from_address,
                'is_pretty': is_pretty
            })
Example #6
0
 def test_is_pretty_from_address_fails_on_bare_address(self):
     """
     Ensure normal email addresses aren't parsed as being "pretty".
     """
     self.assertFalse(is_pretty_from_address('*****@*****.**'))
Example #7
0
 def test_is_pretty_from_succeeds_on_pretty_address(self):
     """
     Ensure pretty addresses (e.g. Foo <*****@*****.**>) are parsed as
     being "pretty".
     """
     self.assertTrue(is_pretty_from_address('Foo <*****@*****.**>'))