'Asserts 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
if the text occurs at least once in the response.'

def assertContains(self, response, text, count=None, status_code=200, msg_prefix=u'', html=False):

    if (hasattr(response, u'render') and callable(response.render) and (not response.is_rendered)):
        response.render()
    if msg_prefix:
        msg_prefix += u':    '
    self.assertEqual(response.status_code, status_code, (msg_prefix + (u"Couldn't    retrieve    content:    Response    code    was    %d    (expected    %d)" % (response.status_code, status_code))))
    if response.streaming:
        content = ''.join(response.streaming_content)
    else:
        content = response.content
    if ((not isinstance(text, bytes)) or html):
        text = force_text(text, encoding=response._charset)
        content = content.decode(response._charset)
        text_repr = (u"'%s'" % text)
    else:
        text_repr = repr(text)
    if html:
        content = assert_and_parse_html(self, content, None, u"Response's    content    is    not    valid    HTML:")
        text = assert_and_parse_html(self, text, None, u'Second    argument    is    not    valid    HTML:')
    real_count = content.count(text)
    if (count is not None):
        self.assertEqual(real_count, count, (msg_prefix + (u'Found    %d    instances    of    %s    in    response    (expected    %d)' % (real_count, text_repr, count))))
    else:
        self.assertTrue((real_count != 0), (msg_prefix + (u"Couldn't    find    %s    in    response" % text_repr)))
