1
0
mirror of https://github.com/django/django.git synced 2025-11-07 07:15:35 +00:00

Fixed #34658 -- Added SimpleTestCase.assertNotInHTML().

This commit is contained in:
Nicolas Lupien
2023-12-20 11:49:47 -05:00
committed by Mariusz Felisiak
parent 5c6906cef4
commit 2bf46c3825
4 changed files with 37 additions and 8 deletions

View File

@@ -922,14 +922,17 @@ class SimpleTestCase(unittest.TestCase):
msg_prefix += ": "
haystack_repr = safe_repr(haystack)
if count is not None:
self.assertEqual(
real_count,
count,
(
f"{msg_prefix}Found {real_count} instances of {needle!r} (expected "
f"{count}) in the following response\n{haystack_repr}"
),
)
if count == 0:
msg = (
f"{needle!r} unexpectedly found in the following response\n"
f"{haystack_repr}"
)
else:
msg = (
f"Found {real_count} instances of {needle!r} (expected {count}) in "
f"the following response\n{haystack_repr}"
)
self.assertEqual(real_count, count, f"{msg_prefix}{msg}")
else:
self.assertTrue(
real_count != 0,
@@ -939,6 +942,9 @@ class SimpleTestCase(unittest.TestCase):
),
)
def assertNotInHTML(self, needle, haystack, msg_prefix=""):
self.assertInHTML(needle, haystack, count=0, msg_prefix=msg_prefix)
def assertJSONEqual(self, raw, expected_data, msg=None):
"""
Assert that the JSON fragments raw and expected_data are equal.