Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Django Basics Test Time Test our article detail template

"It looks like Task 1 is no longer passing.", even the first task is the same.

I typed exactly the same line, but when I go back to first task it says "well done"

articles/tests.py
import datetime

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

from .models import Article, Writer

class ArticleDetailViewTestCase(TestCase):
    '''Tests for the Article detail view'''

    def setUp(self):
        self.writer = Writer.objects.create(
            name='Kenneth Love',
            email='kenneth@teamtreehouse.com',
            bio='Your friendly, local Python teacher'
        )
        self.article = Article.objects.create(
          writer=self.writer,
          headline='Article 0',
          content='Something about 0',
          publish_date=datetime.datetime.today()
        )

    def test_detail_template(self):
        '''Make sure the `articles/article_detail.html` template is used'''
        resp2 = self.client.get(reverse('articles:detail', kwargs={'pk': self.article.pk}))
        self.assertTemplateUsed(resp2, 'articles/article_detail.html')

    def test_detail_template_writer(self):
        '''Make sure the article writer's name is in the rendered output'''
        resp = self.client.get(reverse('writer:detail', kwargs={'pk': self.writer.pk}))
        self.assertContains(resp, self.writer.name)
articles/templates/articles/article_detail.html
{% extends 'base.html' %}

{% block content %}
<h1>{{ article.title }}</h1>
<time>{{ article.publish_date }}</time>
<p>By {{ article.writer.name }}</p>
{{ article.content }}
{% endblock %}

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,441 Points

You are very close. In the second test you are still examining the articles detail view. There isn't a "writers detail" view. Using "writer:detail" is raising an error which causes both the task 1 and 2 to fail, hence the "Task 1 is no longer passing".

Changing "writer:detail" to "articles:detail" in the reverse function should fix it.

In general, "Task 1 is no longer passing" usually means a syntax or other error was introduced with new coded add for the current task. The task 1 code itself usually is OK, but can't run due to the error during parsing.

Ah, I misunderstood the question. Thanks.