AssertionError: Lists differ: [] != ['']
======================================================================
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)
#_______________________________________________________________________________
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/deb9b5a4-a466-488a-afd5-56ebeaea97fd%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home