AssertionError: Lists differ: [] != ['<Word: Past polly>']

518 views
Skip to first unread message

Pepsodent Cola

unread,
Oct 26, 2013, 11:53:05 AM10/26/13
to django...@googlegroups.com
======================================================================
FAIL: test_index_view_with_a_past_poll (navi_polls.tests.PollViewTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/linux/Django/navi/navi_polls/tests.py", line 115, in test_index_view_with_a_past_poll
    ['<Word: Past polly>']
 
 File "/usr/local/lib/python2.7/dist-packages/django/test/testcases.py", line 797, in assertQuerysetEqual
    return self.assertEqual(list(items), values)
AssertionError: Lists differ: [] != ['<Word: Past polly>']

Second list contains 1 additional elements.
First extra element 0:
<Word: Past polly>

- []
+ ['<Word: Past polly>']

----------------------------------------------------------------------
Ran 13 tests in 0.104s

FAILED (failures=1, errors=3)
Destroying test database for alias 'default'...
#_______________________________________________________________________________



I'm trying to do some unit testing with my code.  But I think I'm using the context variable wrong in my test function.
Can anybody help me?


test.py

    # Past polls
    def test_index_view_with_a_past_poll(self):
        """
        Polls with a pub_date in the past should be displayed on the index page.
        """
        create_poll(rosword="Past polly", days=-30)
        response = self.client.get(reverse('navi_polls:index'))
        self.assertQuerysetEqual(
            response.context['untranslated_words'],
            ['<Word: Past polly>']
        )
#_______________________________________________________________________________



views.py
#_______________________________________________________________________________

def index(request):
    #untranslated_words = Word.objects.filter(direct_transl_word='')

    # Return words (not including those set to be published in the future).
    untranslated_words = Word.objects.filter(direct_transl_word='').filter(
                                             pub_date__lte=timezone.now())

    context = {'untranslated_words':untranslated_words}
    return render(request, 'navi_polls/index.html', context)
#_______________________________________________________________________________











Reply all
Reply to author
Forward
0 new messages