Saturday, June 29, 2013

How to Test Querysets

I would like to be able to replace the hardcoded repr in the test with an actual queryset.

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(question="Past poll.", days=-30)          response = self.client.get(reverse('polls:index'))          self.assertQuerysetEqual(              response.context['latest_poll_list'],              ['<Poll: Past poll.>']          )    #new  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(question="Past poll.", days=-30)          response = self.client.get(reverse('polls:index'))          self.assertQuerysetEqual(              response.context['latest_poll_list'],              repr(Poll.objects.filter(question="Past poll."))          )

--
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.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment