title: Django unit test mock queryset from related object
body: <p>I have the following function:</p>
  
  <pre><code>import unittest
  from unittest import mock
  
  
  def get_payments(order):
      return order.payments.filter(status='complete').order_by('-date_added)
  </code></pre>
  
  <p>I want to mock the <code>filter</code> method and the <code>order_by</code> to check the arguments with which are called.</p>
  
  <p>I tried:</p>
  
  <pre><code>class TestPayments(unittest.TestCase):
       @mock.patch('path.Order.payments.filter.order_by')
       @mock.patch('path.Order.payments.filter')
       def test_get_payments(self, mock1, mock2):
          mock1.assert_called_with(status='complete')
          mock2.assert_called_with('-date_added')
  </code></pre>
  
  <p>Another mock I tried:</p>
  
  <pre><code>@mock.patch('path.Payment.objects.filter.order_by')
  @mock.patch('path.Payment.objects.filter')
  
  @mock.patch('path.Order.payments.objects.filter.order_by')
  @mock.patch('path.Order.payments.objects.filter')
  </code></pre>
  
  <p>In last two mocks I have an error that <code>path.Order</code> does not exists.
  I already used a direct mock for a query like <code>Payment.objects.filter()</code> and is working, but starting from a related model like <code>Order</code> I failed.</p>
  
  <p>The relationship between <code>Order</code> and <code>Payment</code> is how you would expect, one to many.</p>