# Path: tests/unit/v1/test_base_query.py
# def _make_credentials():
#     import google.auth.credentials
# 
#     return mock.Mock(spec=google.auth.credentials.Credentials)
# 
# Path: tests/unit/v1/test_base_query.py
# def _make_cursor_pb(pair):
#     from google.cloud.firestore_v1 import _helpers
#     from google.cloud.firestore_v1.types import query
# 
#     values, before = pair
#     value_pbs = [_helpers.encode_value(value) for value in values]
#     return query.Cursor(values=value_pbs, before=before)
# 
# Path: tests/unit/v1/test_base_query.py
# def _make_query_response(**kwargs):
#     # kwargs supported are ``skipped_results``, ``name`` and ``data``
#     from google.cloud.firestore_v1.types import document
#     from google.cloud.firestore_v1.types import firestore
#     from google.cloud._helpers import _datetime_to_pb_timestamp
#     from google.cloud.firestore_v1 import _helpers
# 
#     now = datetime.datetime.utcnow()
#     read_time = _datetime_to_pb_timestamp(now)
#     kwargs["read_time"] = read_time
# 
#     name = kwargs.pop("name", None)
#     data = kwargs.pop("data", None)
#     if name is not None and data is not None:
#         document_pb = document.Document(name=name, fields=_helpers.encode_dict(data))
#         delta = datetime.timedelta(seconds=100)
#         update_time = _datetime_to_pb_timestamp(now - delta)
#         create_time = _datetime_to_pb_timestamp(now - 2 * delta)
#         document_pb._pb.update_time.CopyFrom(update_time)
#         document_pb._pb.create_time.CopyFrom(create_time)
# 
#         kwargs["document"] = document_pb
# 
#     return firestore.RunQueryResponse(**kwargs)


import types
import mock
import pytest
from tests.unit.v1.test_base_query import _make_credentials
from tests.unit.v1.test_base_query import _make_cursor_pb
from tests.unit.v1.test_base_query import _make_query_response
    from google.cloud.firestore_v1.query import Query
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud import firestore
    from google.cloud.firestore_v1.base_query import _enum_from_direction
    from google.cloud.firestore_v1.types.document import Document
    from google.cloud.firestore_v1.types.firestore import RunQueryResponse
    from google.cloud.firestore_v1.types.document import Document
    from google.cloud.firestore_v1.types.firestore import RunQueryResponse
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.api_core import exceptions
    from google.api_core import gapic_v1
    from google.cloud.firestore_v1 import _helpers
    from google.cloud.firestore_v1 import transaction
    from google.cloud.firestore_v1.query import CollectionGroup
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.client import Client

    get_response = query.stream()
    assert isinstance(get_response, types.GeneratorType)
    assert list(get_response) == []

    # Verify the mock call.
    parent_path, _ = parent._parent_info()
    firestore_api.run_query.assert_called_once_with(
        request={
            "parent": parent_path,
            "structured_query": query._to_protobuf(),
            "transaction": None,
        },
        metadata=client._rpc_metadata,
    )


def test_query_stream_with_skipped_results():
    # Create a minimal fake GAPIC.
    firestore_api = mock.Mock(spec=["run_query"])

    # Attach the fake GAPIC to a real client.
    client = _make_client()
    client._firestore_api_internal = firestore_api

    # Make a **real** collection reference as parent.
    parent = client.collection("talk", "and", "chew-gum")

    # Add two dummy responses to the minimal fake GAPIC.
    _, expected_prefix = parent._parent_info()

# Path: tests/unit/v1/test_base_query.py
# def _make_credentials():
#     import google.auth.credentials
# 
#     return mock.Mock(spec=google.auth.credentials.Credentials)
# 
# Path: tests/unit/v1/test_base_query.py
# def _make_cursor_pb(pair):
#     from google.cloud.firestore_v1 import _helpers
#     from google.cloud.firestore_v1.types import query
# 
#     values, before = pair
#     value_pbs = [_helpers.encode_value(value) for value in values]
#     return query.Cursor(values=value_pbs, before=before)
# 
# Path: tests/unit/v1/test_base_query.py
# def _make_query_response(**kwargs):
#     # kwargs supported are ``skipped_results``, ``name`` and ``data``
#     from google.cloud.firestore_v1.types import document
#     from google.cloud.firestore_v1.types import firestore
#     from google.cloud._helpers import _datetime_to_pb_timestamp
#     from google.cloud.firestore_v1 import _helpers
# 
#     now = datetime.datetime.utcnow()
#     read_time = _datetime_to_pb_timestamp(now)
#     kwargs["read_time"] = read_time
# 
#     name = kwargs.pop("name", None)
#     data = kwargs.pop("data", None)
#     if name is not None and data is not None:
#         document_pb = document.Document(name=name, fields=_helpers.encode_dict(data))
#         delta = datetime.timedelta(seconds=100)
#         update_time = _datetime_to_pb_timestamp(now - delta)
#         create_time = _datetime_to_pb_timestamp(now - 2 * delta)
#         document_pb._pb.update_time.CopyFrom(update_time)
#         document_pb._pb.create_time.CopyFrom(create_time)
# 
#         kwargs["document"] = document_pb
# 
#     return firestore.RunQueryResponse(**kwargs)


# Path: tests/unit/v1/test_query.py
import types
import mock
import pytest
from tests.unit.v1.test_base_query import _make_credentials
from tests.unit.v1.test_base_query import _make_cursor_pb
from tests.unit.v1.test_base_query import _make_query_response
    from google.cloud.firestore_v1.query import Query
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud import firestore
    from google.cloud.firestore_v1.base_query import _enum_from_direction
    from google.cloud.firestore_v1.types.document import Document
    from google.cloud.firestore_v1.types.firestore import RunQueryResponse
    from google.cloud.firestore_v1.types.document import Document
    from google.cloud.firestore_v1.types.firestore import RunQueryResponse
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.api_core import exceptions
    from google.api_core import gapic_v1
    from google.cloud.firestore_v1 import _helpers
    from google.cloud.firestore_v1 import transaction
    from google.cloud.firestore_v1.query import CollectionGroup
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.client import Client


    get_response = query.stream()
    assert isinstance(get_response, types.GeneratorType)
    assert list(get_response) == []

    # Verify the mock call.
    parent_path, _ = parent._parent_info()
    firestore_api.run_query.assert_called_once_with(
        request={
            "parent": parent_path,
            "structured_query": query._to_protobuf(),
            "transaction": None,
        },
        metadata=client._rpc_metadata,
    )


def test_query_stream_with_skipped_results():
    # Create a minimal fake GAPIC.
    firestore_api = mock.Mock(spec=["run_query"])

    # Attach the fake GAPIC to a real client.
    client = _make_client()
    client._firestore_api_internal = firestore_api

    # Make a **real** collection reference as parent.
    parent = client.collection("talk", "and", "chew-gum")

    # Add two dummy responses to the minimal fake GAPIC.
    _, expected_prefix = parent._parent_info()

    response_pb1 = _make_query_response(skipped_results=1)