简体   繁体   中英

Django, how to mock annotate?

I want to mock annotate, to see if it was called and the correct parameters where passed.

My query:

User.object.filter(pk__in=[1,2,3]).annotate(is_banned=F('profile__is_banned'))

Test which is working:

@mock.patch('models.User.objects')
def test_method(mock):
    mock.return_value.filter.return_value = QuerySet()
    method_call()
    self.assertEqual(mock.call_count, 1)
    mock.assert_called_with((pk__in=[1,2,3])

I can't mock the annotate.

注释位于mock.filter.return_value.annotate

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM