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 View Tests

Gilang Ilhami
Gilang Ilhami
12,045 Points

'StepModelTests' object has no attribute 'course'

Trying to create the StepModelTests class, but i got an error saying that

======================================================================                           
ERROR: test_Step_Creation (courses.tests.StepModelTests)                                         
----------------------------------------------------------------------                           
Traceback (most recent call last):                                                               
  File "/home/treehouse/workspace/learning_site/courses/tests.py", line 27, in test_Step_Creation
    course = self.course,                                                                        
AttributeError: 'StepModelTests' object has no attribute 'course'                                

----------------------------------------------------------------------                           
Ran 2 tests in 0.008s                                                                            

FAILED (errors=1)                                                                                
Destroying test database for alias 'default'...  

i don't really understand what's going on

from django.test import TestCase
from django.utils import timezone

from .models import Course, Step

class CourseModelTests(TestCase):
    def test_course_creation(self):
        course = Course.objects.create(
            title = "Pyhton Reqular Expressions",
            description = "Learn to write regular expressions in Pyhton"
        )

        now = timezone.now()
        self.assertLess(course.created_at, now)

class StepModelTests(TestCase):
    def setUp(self):
        self.course = Course.objects.create(
            title = "Python Testing",
            description = "Learn to write python tests",
        )

    def test_Step_Creation(self):
        step = Step.objects.create(
            title = "Introduction to Doctests",
            description = "Learn to write tests in the doc string",
            course = self.course,
        )
        self.assertIn(step, self.course.step_set.all())