﻿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
23300	TestCase.assertTemplateUsed passes erroneously on an HttpResponse	Benjamin  Zagorsky	Davide Ceretti	"The following test should fail.  It is asserting that the response both renders and does not render the template ""xxx.html"", which is a contradiction.  However, this test passes.

{{{
from django.test import TestCase
from django.http.response import HttpResponse

class TestTemplateUsed(TestCase):
    def test_template_used(self):
        response = HttpResponse(""xxx"")
        self.assertTemplateUsed(response, ""xxx.html"")
        self.assertTemplateNotUsed(response, ""xxx.html"")
}}}

The issue is that HttpResponse objects have no ""template"" attribute, which assertTemplateUsed interprets as an intention to use a context manager rather than an assertion.  

{{{
def assertTemplateUsed(self, response=None, template_name=None, msg_prefix=''):
    #...
    if not hasattr(response, 'templates') or (response is None and template_name):
        #...
}}}

I'm not sure why this is implemented this way, but from the docs (I can only find the 1.5 docs of this feature; I'm not sure where the relevant docs are for 1.6 and later), it seems far more sensible to implement this as:

{{{
def assertTemplateUsed(self, response=None, template_name=None, msg_prefix=''):
    #...
    if (response is None and template_name):
        #...
}}}

Just to call out an important point, unless I am missing something, this feature is entirely undocumented in v1.6 and v1.7"	Bug	closed	Testing framework	dev	Normal	fixed	asserttemplateused template		Accepted	1	1	1	1	0	0
