Assert that a response indicates that some content was retrieved successfully, (i.e., the HTTP status code was as expected) and that ``text`` occurs ``count`` times in the content of the response. If ``count`` is None, the count doesn't matter - the assertion is true
(
self, response, text, count=None, status_code=200, msg_prefix="", html=False
)
| 594 | return real_count, msg_prefix, response_content |
| 595 | |
| 596 | def assertContains( |
| 597 | self, response, text, count=None, status_code=200, msg_prefix="", html=False |
| 598 | ): |
| 599 | """ |
| 600 | Assert that a response indicates that some content was retrieved |
| 601 | successfully, (i.e., the HTTP status code was as expected) and that |
| 602 | ``text`` occurs ``count`` times in the content of the response. |
| 603 | If ``count`` is None, the count doesn't matter - the assertion is true |
| 604 | if the text occurs at least once in the response. |
| 605 | """ |
| 606 | real_count, msg_prefix, response_content = self._assert_contains( |
| 607 | response, text, status_code, msg_prefix, html |
| 608 | ) |
| 609 | |
| 610 | if (count is None and real_count > 0) or ( |
| 611 | (count is not None and real_count == count) |
| 612 | ): |
| 613 | return |
| 614 | |
| 615 | text_repr = self._text_repr(text, force_string=html) |
| 616 | |
| 617 | if count is not None: |
| 618 | msg = ( |
| 619 | f"{real_count} != {count} : {msg_prefix}Found {real_count} instances " |
| 620 | f"of {text_repr} (expected {count}) in the following response\n" |
| 621 | f"{response_content!r}" |
| 622 | ) |
| 623 | else: |
| 624 | msg = ( |
| 625 | f"False is not true : {msg_prefix}Couldn't find {text_repr} in the " |
| 626 | f"following response\n{response_content!r}" |
| 627 | ) |
| 628 | self.fail(msg) |
| 629 | |
| 630 | def assertNotContains( |
| 631 | self, response, text, status_code=200, msg_prefix="", html=False |
no test coverage detected