Mocking Django queryset

580 views
Skip to first unread message

Boris Ozegovic

unread,
Jun 1, 2014, 5:26:11 AM6/1/14
to django...@googlegroups.com
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

Reply all
Reply to author
Forward
0 new messages