Ticket #10183: 10183-django.test.testcases_assertContainsPatch.3.diff

File 10183-django.test.testcases_assertContainsPatch.3.diff, 1.5 KB (added by trbs, 15 years ago)
  • django/test/testcases.py

    diff -r ed807b5fa10f django/test/testcases.py
    a b  
    1212from django.test import _doctest as doctest
    1313from django.test.client import Client
    1414from django.utils import simplejson
     15from django.utils.encoding import smart_str
    1516
    1617normalize_long_ints = lambda s: re.sub(r'(?<![\w])(\d+)L(?![\w])', '\\1', s)
    1718normalize_decimals = lambda s: re.sub(r"Decimal\('(\d+(\.\d*)?)'\)", lambda m: "Decimal(\"%s\")" % m.groups()[0], s)
     
    330331        self.assertEqual(response.status_code, status_code,
    331332            "Couldn't retrieve page: Response code was %d (expected %d)'" %
    332333                (response.status_code, status_code))
     334        text = smart_str(text, response._charset)
    333335        real_count = response.content.count(text)
    334336        if count is not None:
    335337            self.assertEqual(real_count, count,
     
    348350        self.assertEqual(response.status_code, status_code,
    349351            "Couldn't retrieve page: Response code was %d (expected %d)'" %
    350352                (response.status_code, status_code))
    351         self.assertEqual(response.content.count(text), 0,
    352                          "Response should not contain '%s'" % text)
     353        text = smart_str(text, response._charset)
     354        self.assertEqual(response.content.count(text),
     355             0, "Response should not contain '%s'" % text)
    353356
    354357    def assertFormError(self, response, form, field, errors):
    355358        """
Back to Top