Hi folks,
I am a beginner and am getting started with django, while following tutorial 5 in the test test_no_questions I am getting the following error
"Traceback (most recent call last):
File "C:\Users\Varsh\OneDrive\Documents\django\mysite\polls\tests.py", line 39, in test_no_questions
self.assertQuerySetEqual(response.context["latest_question_list"], [])
File "C:\Users\Varsh\OneDrive\Documents\django\venv\Lib\site-packages\django\test\testcases.py", line 1260, in assertQuerySetEqual
return self.assertEqual(list(items), values, msg=msg)
^^^^^^^^^^^
TypeError: 'method' object is not iterable"
Index View:
class IndexView(generic.ListView):
template_name = "polls/index.html"
context_object_name = "latest_question_list"
def queryset(self):
"""Return the last five published questions."""
return Question.objects.filter(pub_date__lte = timezone.now()).order_by("-pub_date")[:5]
IndexViewTest:
def create_question(question_text,days):
time = timezone.now() + datetime.timedelta(days=days)
return Question.objects.create(question_text=question_text,pub_date=time)
class QuestionIndexViewTest(TestCase):
def test_no_questions(self):
""" If no questions present, appropriate message should be displayed"""
response = self.client.get(reverse("polls:index"))
self.assertEqual(response.status_code,200)
self.assertContains(response,"There are no polls available")
self.assertQuerySetEqual(response.context["latest_question_list"](), [])
# self.assertQuerySetEqual(response.context["latest_question_list"],[])
However it works when I write response.context"latest_question_list". So I think response.context[“latest_question_list”] is a method here. Have I done something wrong or the implementation of querySet method has been changed?