def test_batch_get_documents(self):
        # Setup Expected Response
        missing = "missing1069449574"
        transaction = b"-34"
        expected_response = {"missing": missing, "transaction": transaction}
        expected_response = firestore_pb2.BatchGetDocumentsResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[iter([expected_response])])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = firestore_client.FirestoreClient()

        # Setup Request
        database = client.database_root_path("[PROJECT]", "[DATABASE]")
        documents = []

        response = client.batch_get_documents(database, documents)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        expected_request = firestore_pb2.BatchGetDocumentsRequest(
            database=database, documents=documents)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 2
0
def _make_batch_response(**kwargs):
    from google.cloud.firestore_v1.proto import firestore_pb2

    return firestore_pb2.BatchGetDocumentsResponse(**kwargs)