MCPcopy
hub / github.com/django/django / assertInHTML

Method assertInHTML

django/test/testcases.py:992–1024  ·  view source on GitHub ↗
(self, needle, haystack, count=None, msg_prefix="")

Source from the content-addressed store, hash-verified

990 self.fail(self._formatMessage(msg, standardMsg))
991
992 def assertInHTML(self, needle, haystack, count=None, msg_prefix=""):
993 parsed_needle = assert_and_parse_html(
994 self, needle, None, "First argument is not valid HTML:"
995 )
996 parsed_haystack = assert_and_parse_html(
997 self, haystack, None, "Second argument is not valid HTML:"
998 )
999 real_count = parsed_haystack.count(parsed_needle)
1000
1001 if (count is None and real_count > 0) or count == real_count:
1002 return
1003
1004 if msg_prefix:
1005 msg_prefix += ": "
1006 haystack_repr = safe_repr(haystack)
1007 if count is not None:
1008 if count == 0:
1009 msg = (
1010 f"{needle!r} unexpectedly found in the following response\n"
1011 f"{haystack_repr}"
1012 )
1013 else:
1014 msg = (
1015 f"Found {real_count} instances of {needle!r} (expected {count}) in "
1016 f"the following response\n{haystack_repr}"
1017 )
1018 msg = f"{real_count} != {count} : {msg_prefix}{msg}"
1019 else:
1020 msg = (
1021 f"False is not true : {msg_prefix}Couldn't find {needle!r} in the "
1022 f"following response\n{haystack_repr}"
1023 )
1024 self.fail(msg)
1025
1026 def assertNotInHTML(self, needle, haystack, msg_prefix=""):
1027 self.assertInHTML(needle, haystack, count=0, msg_prefix=msg_prefix)

Callers 15

assertNotInHTMLMethod · 0.95
test_needle_msgMethod · 0.80
test_msg_prefixMethod · 0.80
test_count_msg_prefixMethod · 0.80
test_baseMethod · 0.80
test_long_haystackMethod · 0.80
test_no_requestMethod · 0.80
test_no_exceptionMethod · 0.80

Calls 2

assert_and_parse_htmlFunction · 0.85
countMethod · 0.45

Tested by

no test coverage detected