﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
21480	assertContains(…, html=True) does not work as expected	Jannis Vajen	nobody	"Excuse me if I'm opening a bug report for an intended feature right now, but I'm surprised that `SimpleTestClient.assertContains(…, html=True)` does not find strings when they're present.


{{{#!python
    def test_no_tags(self):
        response = self.client.get(""/view/?content=this is a response"")
        self.assertContains(response, ""response"")

    def test_no_tags_html(self):
        response = self.client.get(""/view/?content=this is a response"")
        self.assertContains(response, ""response"", html=True)

    def test_tag_in_response(self):
        response = self.client.get(""/view/?content=this is a <span>response</span>"")
        self.assertContains(response, ""response"")

    def test_tag_in_response_html(self):
        response = self.client.get(""/view/?content=this is a <span>response</span>"")
        self.assertContains(response, ""response"", html=True)

    def test_tag_in_needle_and_reponse(self):
        response = self.client.get(""/view/?content=this is a <span>response</span>"")
        self.assertContains(response, ""<span>response</span>"")

    def test_tag_in_needle_and_reponse_html(self):
        response = self.client.get(""/view/?content=this is a <span> response</span>"")
        self.assertContains(response, ""<span>response</span>"", html=True)
}}}


{{{
.F...F
======================================================================
FAIL: test_no_tags_html
----------------------------------------------------------------------
Traceback (most recent call last):
 in test_no_tags_html
    self.assertContains(response, ""response"", html=True)
  File ""django/test/testcases.py"", line 664, in assertContains
    msg_prefix + ""Couldn't find %s in response"" % text_repr)
AssertionError: Couldn't find 'response' in response

======================================================================
FAIL: test_tag_in_response_html
----------------------------------------------------------------------
Traceback (most recent call last):
  in test_tag_in_response_html
    self.assertContains(response, ""response"", html=True)
  File ""django/test/testcases.py"", line 664, in assertContains
    msg_prefix + ""Couldn't find %s in response"" % text_repr)
AssertionError: Couldn't find 'response' in response

----------------------------------------------------------------------
Ran 6 tests in 0.026s

FAILED (failures=2)
}}}

It seems that the argument `text` in `TestCase.assertContains(response, text, count=None, status_code=200, msg_prefix='', html=False)` needs to have tags present to match which is not always the case although whitespace (especially newlines) should be ignored.
"	Bug	closed	Testing framework	1.6	Normal	invalid			Unreviewed	0	0	0	0	0	0
