I have a view:
class DashboardView(TemplateView):
template_name = "dashboard/dashboard.html"
Which I am testing using TestCase:
class TestAuthorisedViews(TestCase):
@classmethod
def setUpTestData(cls):
cls.url = reverse('dashboard')
cls.client = Client()
cls.response = cls.client.get(cls.url)
def test_view_uses_correct_template(self):
print('template', self.response.__dict__)
self.assertTemplateUsed(self.response, 'dashboard/dashboard.html')
This test fails with AssertionError: No templates used to render the response.
However, the print() debug I included in the test reveals the response does use a template:
template {'template_name': ['dashboard/dashboard.html'], 'context_data': {
'view': <dashboard.views.DashboardView object at 0x0000019E9CF33040> }, // etc >}
Am I using this test correctly? When looking at the source code, it seems the error fails because response.templates = [] rather than response.templates = None.