[Answered ]-How do you assert that Django's QuerySet.count() method was called on a Mock?

2👍

A call is also a tuple and so can be compared with a tuple:

>>> MockModel.assert_has_calls([
        call.objects.filter(foo='bar'),
        ('objects.filter().count',),
    ])

You can confirm this:

>>> map(tuple, MockModel.mock_calls)
  > [('objects.filter', (), {'foo': 'bar'}), ('objects.filter().count', (), {})]

Source: https://code.google.com/p/mock/source/browse/mock.py#1988

Leave a comment