Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django assertTemplateUsed() throws exception with Jinja templates

When I try to run this test:

from django.test import TestCase
from django.core.urlresolvers import reverse
from django.test import Client

class StatisticTest(TestCase):
    def setUp(self):
        self.client = Client()

    def test_schedule_view(self):
        url = reverse('schedule')
        response = self.client.get(url)
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'schedule.html')

I get AssertionError: No templates used to render the response.

It's my view:

class Schedule(View):
    def get(self, request):
        games = add_team_info(query.get_current_schedule())
        if games is not []:
             available_schedules = generate_schedule_list(games[0]["season_type"], games[0]["week"])
             is_available = True
        else:
             available_schedules = []
             is_available = False
        return render_to_response("schedule.html", 
                              {"games": games, "available_schedules": available_schedules, "is_available": is_available})

and urls.py:

url(r'^schedule/$', views.Schedule.as_view(), name='schedule'),
like image 328
Dima Kudosh Avatar asked Sep 27 '22 06:09

Dima Kudosh


1 Answers

Your problem is that assertTemplateUsed only works with Django templates, not with Jinja templates.

There's an open ticket 24622 about this issue.

like image 191
Alasdair Avatar answered Oct 13 '22 01:10

Alasdair