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


jasper printemps
jasper printemps
4,398 Points

CourseViewsTests Object has no atribute 'course'

i cant figure out why the tests fail i hope someone can help me out

class CourseViewsTests(TestCase):

 def SetUp(self):
     self.course = Course.objects.create(
         title="Python Testing",
         description="Learn to write tests in Python"

     self.course2 = Course.objects.create(
         title="New Course",
         description="A new course"

     self.step = Step.objects.create(
         title="Introduction to Doctests",
         description="Learn to write tests in docstrings.",

 def test_course_list_view(self):
     resp = self.client.get(reverse('courses:list'))
     self.assertEqual(resp.status_code, 200)
     self.assertIn(self.course, resp.context['courses'])
     self.assertIn(self.course2, resp.context['courses'])
     self.assertTemplateUsed(resp, 'courses/course_list.html')
     self.assertContains(resp, self.course.title)

 def test_course_detail_view(self):
     resp = self.client.get(reverse('courses:detail',
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(self.course, resp.context['course'])
     self.assertTemplateUsed(resp, 'courses/course_detail.html')
     self.assertContains(resp, self.course.title)

 def test_step_detail_view(self):
     resp = self.client.get(reverse('courses:step', kwargs={
                                    'course_pk': self.course.pk,
                                    'step_pk': self.step.pk}))
     self.assertEqual(resp.status_code, 200)
     self.assertEqual(self.step, resp.context['step'])
     self.assertTemplateUsed(resp, 'courses/step_detail.html')
     self.assertContains(resp, self.step.title)