Django assertTemplateUsed()抛出Jinja模板的异常

时间:2015-07-23 19:54:33

标签: python django testing jinja2 assert

当我尝试运行此测试时:

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')

我得到AssertionError:没有用于呈现响应的模板。

这是我的观点:

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})

和urls.py:

url(r'^schedule/$', views.Schedule.as_view(), name='schedule'),

1 个答案:

答案 0 :(得分:3)

您的问题是assertTemplateUsed仅适用于Django模板,而不适用于Jinja模板。

有关此问题的公开机票24622