How to mock firestore where function in python?

  firebase, google-cloud-firestore, python, unit-testing

I am using firestore with python to write cloud functions. I need to test a function with following query:

from import firestore

MY_COLLECTION_GROUP = firestore.Client(project="my-project").collection_group("my_collection")

def function_to_test(data):
    my_query = (
        MY_COLLECTION_GROUP.where("eventDateTime", "==", data["dateTime"])
            .where("", "==", data["user_id"])
            .where("user.age", ">=", data["valid_age"])
    # fetch results from query and proceed further

To test the above function, I tried to mock MY_COLLECTION_GROUP‘s where function to test the queries. Like this:

from mock import call, patch

def test_function_to_test(mocked_where_function):
    # called the function with some data

    # tried asserting the mock calls like this
        call("eventDateTime", "==", data["dateTime"]),
        call("", "==", data["user_id"]),
        call("user.age", ">=", data["valid_age"]),

But it seems like it was only mocking the first where function and not all, I got the following error while running test:

E               AssertionError: Calls not found.
E               Expected: [call('eventDateTime', '==', '2021, 09, 15'),
E                call('', '==', '12'),
E                call('user.age', '>=', 18)]
E               Actual: [call('eventDateTime', '==', '2021, 09, 15'),
E                call().where('', '==', '12'),
E                call().where().where('user.age', '>=', 18))]

So, is there any way to mock all where functions and not just the first one?

What am I doing wrong here?

Source: Python Questions