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 list view

Why does this python test code produce the error "Didn't find 'self.assertIn' used" ?

The final line uses self.assertIn(). Thanks in advance!

import datetime

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

from .models import Article, Writer

class ArticleListViewTestCase(TestCase):
    '''Tests for the Article list 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()
        )
        for x in range(1, 3):
            Article.objects.create(
                writer=self.writer,
                headline='Article {}'.format(x),
                content='Something about {}'.format(x),
                publish_date=datetime.datetime.today()
            )

    def test_all_article_return(self):
        resp = self.client.get(reverse('articles:list'))
        self.assertIn( self.article, resp.context['articles'] )

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,457 Points

Sorry to say, but the challenge checker is completely overbearing on this one. Your code is correct, but the checker doesn't like the spaces inside the parens. This passes:

    def test_all_article_return(self):
        resp = self.client.get(reverse('articles:list'))
        self.assertIn(self.article, resp.context['articles'])  # <-- spaces removed from inside of parens

Tagging Kenneth Love: Can the checker be relaxed on the spaces checking?

This worked. Thanks so much!

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Done...but you really shouldn't use spaces like that.

Chris Freeman
Chris Freeman
Treehouse Moderator 68,457 Points

Thanks Kenneth! What do you think about adding a "PEP-8" pre-check to all challenge grading, then error with "Fix PEP-8 errors before continuing. Error: nnn"

It will promote good coding and may simplify challenge validators.

Kenneth Love
Kenneth Love
Treehouse Guest Teacher

Chris Freeman while I'd love that, it would have to be an opt-in thing per challenge since, say, Python Basics students can't be expected to do PEP-8 compliant code right out of the box. So then I'd have to go back through all of the code challenges and add this in and...time :)