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'))
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 })
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})
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})
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 })
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('*****@*****.**'))
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 <*****@*****.**>'))