Code

#19681 closed Cleanup/optimization (invalid)

documentation bug: tutorial 5

Reported by: upadhyay@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

Under Testing our new view: https://docs.djangoproject.com/en/dev/intro/tutorial05/#testing-our-new-view, class PollViewTests, method test_index_view_with_a_past_poll is wrong. It is currently:

    def test_index_view_with_a_past_poll(self):
        """
        Polls with a pub_date in the past should be displayed on the index page.
        """
        create_poll(question="Past poll.", days=-30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_poll_list'],
            ['<Poll: Past poll.>']
        )

This is wrong, correct version:

    def test_index_view_with_a_past_poll(self):
        """
        Polls with a pub_date in the past should be displayed on the index page.
        """
        past_poll = create_poll(question="Past poll.", days=-30)
        response = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            response.context['latest_poll_list'],
            [past_poll]
        )

There are a few other instances of this mistake in the subsequent tests.

Attachments (0)

Change History (3)

comment:1 Changed 15 months ago by aaugustin

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

Could you paste the output of the failing test?

comment:2 Changed 15 months ago by Amit Upadhyay <upadhyay@…>

As you can see from tutorial 3, latest_poll_list is a list of polls:

latest_poll_list = Poll.objects.order_by('-pub_date')[:5]

Where as in the test in tutorial 5 it is compared with a list of strings. So either assertQuerysetEqual is a funny creature or there is a bug in test example.

comment:3 Changed 15 months ago by aaugustin

  • Resolution set to invalid
  • Status changed from new to closed

May I suggest reading the docs :)

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.