Opened 11 years ago

Closed 11 years ago

#19681 closed Cleanup/optimization (invalid)

documentation bug: tutorial 5

Reported by: upadhyay@… Owned by: nobody
Component: Documentation Version: dev
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.

Change History (3)

comment:1 by Aymeric Augustin, 11 years ago

Could you paste the output of the failing test?

comment:2 by Amit Upadhyay <upadhyay@…>, 11 years ago

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 by Aymeric Augustin, 11 years ago

Resolution: invalid
Status: newclosed

May I suggest reading the docs :)

Note: See TracTickets for help on using tickets.
Back to Top