# IndexView test not working (method object not iterable error)

**URL:** <https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987>\
**Category:** Getting Started\
**Created:** [October 27, 2024, 12:43am UTC](https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987 "2024-10-27T00:43:01Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varshni11](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/varshni11/32/24830_2.png) [@Varshni11](https://forum.djangoproject.com/u/Varshni11)\
**Post date:** [October 27, 2024, 12:43am UTC](https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987/1 "2024-10-27T00:43:01Z")

</div>

Hi folks,  
I am a beginner and am getting started with django, while following [tutorial 5](https://docs.djangoproject.com/en/5.1/intro/tutorial05/#:~:text=Testing%20our%20new%20view%C2%B6) in the test test\_no\_questions I am getting the following error

```auto
"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:

```auto
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:

```auto
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?

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 27, 2024, 12:48am UTC](https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987/3 "2024-10-27T00:48:27Z")

</div>

Side Note: When posting code here, enclose the code between lines of three  
backtick - ` characters. This means you’ll have a line of ```, then your code,  
then another line of ```. This forces the forum software to keep your code  
properly formatted. (I have taken the liberty of correcting your original posts.  
Please remember to do this in the future.)

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [October 27, 2024, 12:53am UTC](https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987/4 "2024-10-27T00:53:26Z")

</div>

Your view is defined incorrectly.

Carefully compare what you have defined in `IndexView` with what’s defined at [poll/views.py](https://docs.djangoproject.com/en/5.1/intro/tutorial05/#id4), and correct the difference.

---

<div class="post-metadata">

**Author:** ![Varshni11](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/varshni11/32/24830_2.png) [@Varshni11](https://forum.djangoproject.com/u/Varshni11)\
**Post date:** [October 27, 2024, 12:59am UTC](https://forum.djangoproject.com/t/indexview-test-not-working-method-object-not-iterable-error/35987/5 "2024-10-27T00:59:32Z")

</div>

Thanks for formatting my post. I will keep in mind for future posts. I have actually got what I have done wrong. I have gotten the method name wrong in the IndexView. ( used queryset instead of get\_queryset)
