Consider the following test method:
@patch("api.views.my_views.MyViewSet.send_customer_request")
def test_process_customers(self, send_customer_request_mock):
process_customers(123, 456)
# The above call eventually results in a call to send_customer_request
# Note that my test does NOT call send_customer_request() directly. It's a couple calls deep.
expected_params = {
"names": ["Rupert", "Steve"],
}
send_customer_request_mock.assert_called_with(expected_params)
This test passes some of the time, and fails other times. The problem is that the order of the names is nondeterministic. Sometimes it is called with ["Rupert", "Steve"], and sometimes it is called with ["Steve", "Rupert"].
I need to assert that exactly those two names are in the list, but without requiring the specific order that they're in.
Unfortunately, assert_called_with() expects a single exact value for the mocked method to be called with, but it's impossible to know exactly what it will be.
Ideally, I'd like to just retrieve the values that send_customer_request() gets called with, and then write my own assert statements/logic to test the values.
How can I achieve that?