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.
--
Ticket URL: <https://code.djangoproject.com/ticket/31476>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
Ticket URL: <https://code.djangoproject.com/ticket/31476#comment:1>
* status: new => closed
* resolution: => invalid
* easy: 0 => 1
Comment:
Hello Anthony,
I think you just have a typo in your `create_question` function : yours
has `time = timezone.now() - datetime.timedelta(days=days)` whereas the
tutorial has `time = timezone.now() + datetime.timedelta(days=days)`. That
explains why your past and future are in the wrong place ;)
--
Ticket URL: <https://code.djangoproject.com/ticket/31476#comment:2>
Comment (by dasbairagya):
this is my case but no luck
{{{
def create_question(question_text, days):
"""
Create a question with the given `question_text` and published the
given number of `days` offset to now (negative for questions published
in the past, positive for questions that have yet to be published).
"""
time = timezone.now() + datetime.timedelta(days=days)
return Question.objects.create(question_text=question_text,
pub_date=time)
}}}
please have a look here
https://code.djangoproject.com/ticket/32816#comment:2
--
Ticket URL: <https://code.djangoproject.com/ticket/31476#comment:3>