Skip to content

Commit

Permalink
Merge branch 'release-2.5.x' into release-2.6.x
Browse files Browse the repository at this point in the history
  • Loading branch information
Barret Rennie committed Aug 27, 2015
2 parents 192a69a + 0061d7a commit c9edc2c
Showing 1 changed file with 19 additions and 27 deletions.
46 changes: 19 additions & 27 deletions reviewboard/notifications/tests.py
@@ -1,6 +1,6 @@
from __future__ import unicode_literals

from contextlib import contextmanager
import logging

from django.conf import settings
from django.contrib.auth.models import User
Expand Down Expand Up @@ -34,23 +34,7 @@
from reviewboard.testing import TestCase


@contextmanager
def console_email_backend():
"""Wrap code that should use the console e-mail backend.
The test e-mail backend won't encounter some of the unicode processing
errors that can happen with other backends (like SMTP or console). This
context manager can wrap test code that depends on this behavior, and will
clean up after itself.
"""
old_backend = settings.EMAIL_BACKEND
settings.EMAIL_BACKEND = \
'django.core.mail.backends.console.EmailBackend'

try:
yield
finally:
settings.EMAIL_BACKEND = old_backend
_CONSOLE_EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'


class EmailTestHelper(object):
Expand Down Expand Up @@ -120,7 +104,7 @@ def test_new_user_email(self):
admin_email_addr))


class ReviewRequestEmailTests(EmailTestHelper, TestCase):
class ReviewRequestEmailTests(EmailTestHelper, SpyAgency, TestCase):
"""Tests the e-mail support."""

fixtures = ['test_users']
Expand Down Expand Up @@ -633,22 +617,27 @@ def test_local_site_user_filters(self):

def test_review_request_email_with_unicode_summary(self):
"""Testing sending a review request e-mail with a unicode subject"""
# Because the console backend won't populate mail.outbox, we just rely
# on the fact that we don't get a UnicodeDecodeError here.
with console_email_backend():
self.spy_on(logging.exception)

with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
review_request = self.create_review_request()
review_request.summary = '\ud83d\ude04'

review_request.target_people.add(User.objects.get(username='grumpy'))
review_request.target_people.add(User.objects.get(
username='grumpy'))
review_request.target_people.add(User.objects.get(username='doc'))
review_request.publish(review_request.submitter)

self.assertIsNotNone(review_request.email_message_id)
self.assertFalse(logging.exception.spy.called)

def test_review_request_email_with_unicode_description(self):
"""Testing sending a review request e-mail with a unicode
description"""
# Because the console backend won't populate mail.outbox, we just rely
# on the fact that we don't get a UnicodeDecodeError here.
with console_email_backend():
description
"""
self.spy_on(logging.exception)

with self.settings(EMAIL_BACKEND=_CONSOLE_EMAIL_BACKEND):
review_request = self.create_review_request()
review_request.description = '\ud83d\ude04'

Expand All @@ -658,6 +647,9 @@ def test_review_request_email_with_unicode_description(self):
User.objects.get(username='doc'))
review_request.publish(review_request.submitter)

self.assertIsNotNone(review_request.email_message_id)
self.assertFalse(logging.exception.spy.called)

@add_fixtures(['test_scmtools'])
def test_review_request_email_with_added_file(self):
"""Testing sending a review request e-mail with added files in the
Expand Down

0 comments on commit c9edc2c

Please sign in to comment.