sandiegopython/test-driven-django-development

Add to "We should add a test for that..."

riseriyo opened this issue · 1 comments

Suggestion: add to "We should add a test for that... " under section, Updating our views,

Change to:
"We should add a test for that in our class HomePageTests"

In the code example to add tests, I would also suggest that you clearify the code example. It should be made clear that the test file already has existing code that the test and import should be appended with:

from django.contrib.auth import get_user_model
.
.
.
.
class HomePageTests(TestCase):

"""Test whether our blog entries show up on the homepage"""

def setUp(self):
    self.user = get_user_model().objects.create(username='some_user')

def test_one_entry(self):
    Entry.objects.create(title='1-title', body='1-body', author=self.user)
    response = self.client.get('/')
    self.assertContains(response, '1-title')
    self.assertContains(response, '1-body')

def test_two_entries(self):
    Entry.objects.create(title='1-title', body='1-body', author=self.user)
    Entry.objects.create(title='2-title', body='2-body', author=self.user)
    response = self.client.get('/')
    self.assertContains(response, '1-title')
    self.assertContains(response, '1-body')
    self.assertContains(response, '2-title')