As you can see, when I run the tests.py I fail due to the queryset having quotes around each entry and the question does not. I am not sure if the view is causing it but I’m frustrated. Ive tried a lot of ways to add quotes to the question or remove quotes from the queryset but none worked.
Failure:
FAIL: test_future_question_and_past_question (polls.tests.QuestionIndexViewTests)
Even if both past and future questions exist, only past questions
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/sio/djangotutorial/polls/tests.py", line 92, in test_future_question_and_past_question
self.assertQuerysetEqual(qs, [question])
File "/home/sio/.local/lib/python3.9/site-packages/django/test/testcases.py", line 1052, in assertQuerysetEqual
return self.assertEqual(list(items), values, msg=msg)
AssertionError: Lists differ: ['<Question: Past question.>'] != [<Question: Past question.>]
First differing element 0:
'<Question: Past question.>'
<Question: Past question.>
- ['<Question: Past question.>']
? - -
+ [<Question: Past question.>]
Indexview in views.py
Method in tests.py:
def test_future_question_and_past_question(self):
"""
Even if both past and future questions exist, only past questions
are displayed.
"""
question = create_question(question_text="Past question.", days=-30)
create_question(question_text="Future question.", days=30)
response = self.client.get(reverse("polls:index"))
self.assertQuerysetEqual(response.context["latest_question_list"], [question],)