diff --git a/django/test/testcases.py b/django/test/testcases.py
index a55bb60..358cb3f 100644
a
|
b
|
class TransactionTestCase(SimpleTestCase):
|
614 | 614 | self.assertEqual(response.status_code, status_code, |
615 | 615 | msg_prefix + "Couldn't retrieve content: Response code was %d" |
616 | 616 | " (expected %d)" % (response.status_code, status_code)) |
617 | | text = force_text(text, encoding=response._charset) |
| 617 | |
618 | 618 | if response.streaming: |
619 | 619 | content = b''.join(response.streaming_content) |
620 | 620 | else: |
621 | 621 | 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) |
623 | 625 | if html: |
624 | 626 | content = assert_and_parse_html(self, content, None, |
625 | 627 | "Response's content is not valid HTML:") |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
654 | 656 | self.assertEqual(response.status_code, status_code, |
655 | 657 | msg_prefix + "Couldn't retrieve content: Response code was %d" |
656 | 658 | " (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) |
659 | 664 | if html: |
660 | 665 | content = assert_and_parse_html(self, content, None, |
661 | 666 | 'Response\'s content is not valid HTML:') |
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):
|
131 | 131 | self.assertNotContains(r, 'はたけ') |
132 | 132 | self.assertNotContains(r, b'\xe3\x81\xaf\xe3\x81\x9f\xe3\x81\x91'.decode('utf-8')) |
133 | 133 | |
| 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 | |
134 | 141 | def test_nontext_contains(self): |
135 | 142 | r = self.client.get('/test_client_regress/no_template_view/') |
136 | 143 | self.assertContains(r, ugettext_lazy('once')) |
diff --git a/tests/test_client_regress/urls.py b/tests/test_client_regress/urls.py
index d869c23..1332537 100644
a
|
b
|
urlpatterns = patterns('',
|
28 | 28 | (r'^check_session/$', views.check_session_view), |
29 | 29 | (r'^request_methods/$', views.request_methods_view), |
30 | 30 | (r'^check_unicode/$', views.return_unicode), |
| 31 | (r'^check_binary/$', views.return_undecodable_binary), |
31 | 32 | (r'^parse_unicode_json/$', views.return_json_file), |
32 | 33 | (r'^check_headers/$', views.check_headers), |
33 | 34 | (r'^check_headers_redirect/$', RedirectView.as_view(url='/test_client_regress/check_headers/')), |
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):
|
70 | 70 | def return_unicode(request): |
71 | 71 | return render_to_response('unicode.html') |
72 | 72 | |
| 73 | def 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 | |
73 | 78 | def return_json_file(request): |
74 | 79 | "A view that parses and returns a JSON string as a file." |
75 | 80 | match = CONTENT_TYPE_RE.match(request.META['CONTENT_TYPE']) |