﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31476	Django Tutorial 5 - Testing create_question issue - Assertion Failure	Anthony Davie	nobody	"Firstly, thanks for a great tutorial! I'm really enjoying learning Django.

Secondly, the code in the Testing Tutorial (#6):

{{{
create_question(question_text=""Past question."", days=-30)
}}}

is redundant? This works as well:

{{{
create_question(""Past question."", -30)
}}}

My error is this:

{{{
AssertionError: Lists differ: [] != ['<Question: Past question>']

Second list contains 1 additional elements.
First extra element 0:
'<Question: Past question>'

- []
+ ['<Question: Past question>']

}}}

For future question, I'm getting this:

{{{
AssertionError: Lists differ: ['<Question: Future question>'] != []

First list contains 1 additional elements.
First extra element 0:
'<Question: Future question>'

- ['<Question: Future question>']
+ []
}}}


This is the code for test_past_question:

{{{
def test_past_question(self):
        """"""
        Questions with a published_date in the past.
        """"""
        create_question('Past question', days=-30)

        resp = self.client.get(reverse('polls:index'))
        self.assertQuerysetEqual(
            resp.context['latest'],
            ['<Question: Past question>']
        )
}}}


and my create_question method:

{{{
def create_question(text, days):
    """"""
    Create a Question with text and days from now. -ve in the past, +ve in the future.
    """"""
    time = timezone.now() - datetime.timedelta(days=days)
    q =  Question.objects.create(question_text=text, published_date=time)
    # pr = ""create_question("" + text + "", "" + str(days) + "")""
    # print(pr, q)
    return q

}}}

I've been knocking my head over this for the last few days.
Any help much appreciated.


"	Bug	closed	Documentation	3.0	Normal	invalid	tutorial, testing		Unreviewed	0	0	0	0	1	0
