Sunday, June 1, 2014

Mocking Django queryset

Hi

I am having trouble mocking querysets which contains slice.  Example

qs = Thread.objects.filter(some_filter).order_by(some_order')[:app_settings.SEARCH_LIMIT]

And in my test I have:

Thread.objects.assert_has_calls([
            mock.call.filter('some_filter'),
            mock.call.filter().order_by('some_order'),
            mock.call.filter().order_by().__getitem__(slice(None, 1000, None))
])

But this isn't working.  Message is:

Expected: [call.filter('filter'), call.filter().order_by('-post_counter'), ('filter().order_by', (), {})]
Actual: [call.filter('filter'),
 call.filter().order_by('-post_counter'),
 call.filter().order_by().__getitem__(slice(None, 1000, None))]

Why? 

Python 2.7.5, Django 1.7b4

--
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/90025e4e-b8d6-4e24-9ef1-d2d919d3cd09%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment