Fix unicode error when assertMessageCount() fails

When assertMessageCount() fails, we display the list of messages that
were included in the response. However because the messages are lazily
translated by default, this would fail and show the following error
instead:

 TypeError: sequence item 0: expected string, __proxy__ found

Change-Id: I1d2ed97b66428e0ee1aac783c8370ab3ea665b29
Closes-Bug: #1315031
This commit is contained in:
Julie Pichon 2014-05-01 15:50:32 +01:00
parent 53eb11604b
commit ed9faf84d1

View File

@ -31,6 +31,7 @@ from django.core.handlers import wsgi
from django import http
from django import test as django_test
from django.test.client import RequestFactory # noqa
from django.utils.encoding import force_unicode
from django.utils import unittest
LOG = logging.getLogger(__name__)
@ -154,7 +155,8 @@ class TestCase(django_test.TestCase):
# Otherwise, make sure we got the expected messages.
for msg_type, count in kwargs.items():
msgs = [m.message for m in messages if msg_type in m.tags]
msgs = [force_unicode(m.message)
for m in messages if msg_type in m.tags]
assert len(msgs) == count, \
"%s messages not as expected: %s" % (msg_type.title(),
", ".join(msgs))