diff --git a/django/test/testcases.py b/django/test/testcases.py
index 358cb3f..a9fcc2b 100644
a
|
b
|
class TransactionTestCase(SimpleTestCase):
|
622 | 622 | if not isinstance(text, bytes) or html: |
623 | 623 | text = force_text(text, encoding=response._charset) |
624 | 624 | content = content.decode(response._charset) |
| 625 | text_repr = "'%s'" % text |
| 626 | else: |
| 627 | text_repr = repr(text) |
625 | 628 | if html: |
626 | 629 | content = assert_and_parse_html(self, content, None, |
627 | 630 | "Response's content is not valid HTML:") |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
630 | 633 | real_count = content.count(text) |
631 | 634 | if count is not None: |
632 | 635 | self.assertEqual(real_count, count, |
633 | | msg_prefix + "Found %d instances of '%s' in response" |
634 | | " (expected %d)" % (real_count, text, count)) |
| 636 | msg_prefix + "Found %d instances of %s in response" |
| 637 | " (expected %d)" % (real_count, text_repr, count)) |
635 | 638 | else: |
636 | 639 | self.assertTrue(real_count != 0, |
637 | | msg_prefix + "Couldn't find '%s' in response" % text) |
| 640 | msg_prefix + "Couldn't find %s in response" % text_repr) |
638 | 641 | |
639 | 642 | def assertNotContains(self, response, text, status_code=200, |
640 | 643 | msg_prefix='', html=False): |
… |
… |
class TransactionTestCase(SimpleTestCase):
|
661 | 664 | if not isinstance(text, bytes) or html: |
662 | 665 | text = force_text(text, encoding=response._charset) |
663 | 666 | content = content.decode(response._charset) |
| 667 | text_repr = "'%s'" % text |
| 668 | else: |
| 669 | text_repr = repr(text) |
664 | 670 | if html: |
665 | 671 | content = assert_and_parse_html(self, content, None, |
666 | 672 | 'Response\'s content is not valid HTML:') |
667 | 673 | text = assert_and_parse_html(self, text, None, |
668 | 674 | 'Second argument is not valid HTML:') |
669 | 675 | self.assertEqual(content.count(text), 0, |
670 | | msg_prefix + "Response should not contain '%s'" % text) |
| 676 | msg_prefix + "Response should not contain %s" % text_repr) |
671 | 677 | |
672 | 678 | def assertFormError(self, response, form, field, errors, msg_prefix=''): |
673 | 679 | """ |
diff --git a/tests/test_client_regress/tests.py b/tests/test_client_regress/tests.py
index fe0a410..2582b21 100644
a
|
b
|
class AssertContainsTests(TestCase):
|
133 | 133 | |
134 | 134 | def test_binary_contains(self): |
135 | 135 | r = self.client.get('/test_client_regress/check_binary/') |
136 | | self.assertContains(r, b'PDF document') |
| 136 | self.assertContains(r, b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e') |
137 | 137 | with self.assertRaises(AssertionError): |
138 | | self.assertContains(r, b'PDF document', count=2) |
139 | | self.assertNotContains(r, b'ODF document') |
| 138 | self.assertContains(r, b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e', count=2) |
| 139 | |
| 140 | def test_binary_not_contains(self): |
| 141 | r = self.client.get('/test_client_regress/check_binary/') |
| 142 | self.assertNotContains(r, b'%ODF-1.4\r\n%\x93\x8c\x8b\x9e') |
| 143 | with self.assertRaises(AssertionError): |
| 144 | self.assertNotContains(r, b'%PDF-1.4\r\n%\x93\x8c\x8b\x9e') |
140 | 145 | |
141 | 146 | def test_nontext_contains(self): |
142 | 147 | r = self.client.get('/test_client_regress/no_template_view/') |