#10183: assertContains fails when there is unicode in the response content
----------------------------------------+-----------------------------------
Reporter: drakonen | Owner: nobody
Status: reopened | Milestone: 1.1
Component: Testing framework | Version: 1.0
Resolution: | Keywords: testcases,
assertContains, assertNotContains
Stage: Accepted | Has_patch: 1
Needs_docs: 0 | Needs_tests: 0
Needs_better_patch: 0 |
----------------------------------------+-----------------------------------
Changes (by trbs):
* status: closed => reopened
* resolution: invalid =>
Comment:
The reason the test case did not fail was because the assertion is not
unicode.
I've attached a test case that does fail, it uses some Japanese in the
template and tries to match a Unicode string in assertContains. Also
attached a slight improvement on the patch for testcases.py because before
a failed assertion did not use the smart_str version of the text resulting
in "AssertionError: <unprintable AssertionError object>"
With the new test case it fails as follows:
{{{
======================================================================
ERROR: test_unicode_contains
(regressiontests.test_client_regress.models.AssertContainsTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/home/trbs/django/trunk/tests/regressiontests/test_client_regress/models.py",
line 71, in test_unicode_contains
self.assertContains(r, '\xe5\xb3\xa0'.decode('utf-8'))
File "/home/trbs/django/trunk/django/test/testcases.py", line 333, in
assertContains
real_count = response.content.count(text)
UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 2:
ordinal not in range(128)
----------------------------------------------------------------------
Ran 48 tests in 4.005s
FAILED (errors=1)
Destroying test database...
}}}
Hope this clears things up, otherwise you can also drop me a line on irc
:)
--
Ticket URL: <http://code.djangoproject.com/ticket/10183#comment:7>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---