Answer the question
In order to leave comments, you need to log in
What is the gap in the tests?
Testing templatetags with the following code:
from django.test import TestCase
from django.template import Template, Context
from django.shortcuts import render_to_response
from news.models import News
class NewsTemplatetagsTest(TestCase):
TEMPLATE = Template("{% load news %} {% last %}")
def test_show_last(self):
html = render_to_response('news/last.html', {'data': News.objects.get_list(limit=3)})
rendered = self.TEMPLATE.render(Context({}))
self.assertEquals(html.content.decode('utf8'), rendered)
from django import template
from news.models import News
register = template.Library()
@register.inclusion_tag('news/last.html', takes_context=True)
def last(context):
return {'data': News.objects.get_list(limit=3)}
self.assertEquals(html.content.decode('utf8'), rendered)
AssertionError: '[<News: title_49>, <News: title_48>, <News: title_47>]' != ' [<News: title_49>, <News: title_48>, <News: title_47>]'
self.assertEquals(html.content.decode('utf8'), rendered)
AssertionError: '' != ' '
Answer the question
In order to leave comments, you need to log in
"{% load news %} {% last %}"
You have a space between "{% load news %}" and "{% last %}"
PS Your test is kind of meaningless, because. the tag code and the test code do the same thing. It's like testing assert foo() == foo(). Well, yes, this assert is unlikely to ever break, even if you delete the entire function code, but what is the point is not clear. It is highly desirable that the test does not know anything about the implementation.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question