Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Python

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.",
         course=self.course
     )

 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',
                                    kwargs={'pk':self.course.pk}))
     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)