Ticket #20237: 20237.diff

File 20237.diff, 3.9 KB (added by Claude Paroz, 12 years ago)
  • django/test/testcases.py

    diff --git a/django/test/testcases.py b/django/test/testcases.py
    index a55bb60..358cb3f 100644
    a b class TransactionTestCase(SimpleTestCase):  
    614614        self.assertEqual(response.status_code, status_code,
    615615            msg_prefix + "Couldn't retrieve content: Response code was %d"
    616616            " (expected %d)" % (response.status_code, status_code))
    617         text = force_text(text, encoding=response._charset)
     617
    618618        if response.streaming:
    619619            content = b''.join(response.streaming_content)
    620620        else:
    621621            content = response.content
    622         content = content.decode(response._charset)
     622        if not isinstance(text, bytes) or html:
     623            text = force_text(text, encoding=response._charset)
     624            content = content.decode(response._charset)
    623625        if html:
    624626            content = assert_and_parse_html(self, content, None,
    625627                "Response's content is not valid HTML:")
    class TransactionTestCase(SimpleTestCase):  
    654656        self.assertEqual(response.status_code, status_code,
    655657            msg_prefix + "Couldn't retrieve content: Response code was %d"
    656658            " (expected %d)" % (response.status_code, status_code))
    657         text = force_text(text, encoding=response._charset)
    658         content = response.content.decode(response._charset)
     659
     660        content = response.content
     661        if not isinstance(text, bytes) or html:
     662            text = force_text(text, encoding=response._charset)
     663            content = content.decode(response._charset)
    659664        if html:
    660665            content = assert_and_parse_html(self, content, None,
    661666                'Response\'s content is not valid HTML:')
  • tests/test_client_regress/tests.py

    diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
    index 9972d67..fe0a410 100644
    a b class AssertContainsTests(TestCase):  
    131131        self.assertNotContains(r, 'はたけ')
    132132        self.assertNotContains(r, b'\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8'))
    133133
     134    def test_binary_contains(self):
     135        r = self.client.get('/test_client_regress/check_binary/')
     136        self.assertContains(r, b'PDF document')
     137        with self.assertRaises(AssertionError):
     138            self.assertContains(r, b'PDF document', count=2)
     139        self.assertNotContains(r, b'ODF document')
     140
    134141    def test_nontext_contains(self):
    135142        r = self.client.get('/test_client_regress/no_template_view/')
    136143        self.assertContains(r, ugettext_lazy('once'))
  • tests/test_client_regress/urls.py

    diff --git a/tests/test_client_regress/urls.py b/tests/test_client_regress/urls.py
    index d869c23..1332537 100644
    a b urlpatterns = patterns('',  
    2828    (r'^check_session/$', views.check_session_view),
    2929    (r'^request_methods/$', views.request_methods_view),
    3030    (r'^check_unicode/$', views.return_unicode),
     31    (r'^check_binary/$', views.return_undecodable_binary),
    3132    (r'^parse_unicode_json/$', views.return_json_file),
    3233    (r'^check_headers/$', views.check_headers),
    3334    (r'^check_headers_redirect/$', RedirectView.as_view(url='/test_client_regress/check_headers/')),
  • tests/test_client_regress/views.py

    diff --git a/tests/test_client_regress/views.py b/tests/test_client_regress/views.py
    index 9b06548..7e86ffd 100644
    a b def request_methods_view(request):  
    7070def return_unicode(request):
    7171    return render_to_response('unicode.html')
    7272
     73def return_undecodable_binary(request):
     74    return HttpResponse(
     75        b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e ReportLab Generated PDF document http://www.reportlab.com'
     76    )
     77
    7378def return_json_file(request):
    7479    "A view that parses and returns a JSON string as a file."
    7580    match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE'])
Back to Top