# Path: tests/unit/v1/test__helpers.py
# class AsyncIter:
#     """Utility to help recreate the effect of an async generator. Useful when
#     you need to mock a system that requires `async for`.
#     """
# 
#     def __init__(self, items):
#         self.items = items
# 
#     async def __aiter__(self):
#         for i in self.items:
#             yield i
# 
# Path: tests/unit/v1/test__helpers.py
# class AsyncMock(mock.MagicMock):
#     async def __call__(self, *args, **kwargs):
#         return super(AsyncMock, self).__call__(*args, **kwargs)
# 
# 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_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_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)


import types
import mock
import pytest
from tests.unit.v1.test__helpers import AsyncIter
from tests.unit.v1.test__helpers import AsyncMock
from tests.unit.v1.test_base_query import _make_credentials
from tests.unit.v1.test_base_query import _make_query_response
from tests.unit.v1.test_base_query import _make_cursor_pb
    from google.cloud.firestore_v1.async_query import AsyncQuery
    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 import document
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import document
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_query import AsyncCollectionGroup
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_client import AsyncClient
    await _stream_helper()


@pytest.mark.asyncio
async def test_asyncquery_stream_w_retry_timeout():

    retry = Retry(predicate=object())
    timeout = 123.0
    await _stream_helper(retry=retry, timeout=timeout)


@pytest.mark.asyncio
async def test_asyncquery_stream_with_limit_to_last():
    # Attach the fake GAPIC to a real client.
    client = _make_client()
    # Make a **real** collection reference as parent.
    parent = client.collection("dee")
    # Execute the query and check the response.
    query = _make_async_query(parent)
    query = query.limit_to_last(2)

    stream_response = query.stream()

    with pytest.raises(ValueError):
        [d async for d in stream_response]


@pytest.mark.asyncio
async def test_asyncquery_stream_with_transaction():
    # Create a minimal fake GAPIC.

# Path: tests/unit/v1/test__helpers.py
# class AsyncIter:
#     """Utility to help recreate the effect of an async generator. Useful when
#     you need to mock a system that requires `async for`.
#     """
# 
#     def __init__(self, items):
#         self.items = items
# 
#     async def __aiter__(self):
#         for i in self.items:
#             yield i
# 
# Path: tests/unit/v1/test__helpers.py
# class AsyncMock(mock.MagicMock):
#     async def __call__(self, *args, **kwargs):
#         return super(AsyncMock, self).__call__(*args, **kwargs)
# 
# 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_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_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_async_query.py
import types
import mock
import pytest
from tests.unit.v1.test__helpers import AsyncIter
from tests.unit.v1.test__helpers import AsyncMock
from tests.unit.v1.test_base_query import _make_credentials
from tests.unit.v1.test_base_query import _make_query_response
from tests.unit.v1.test_base_query import _make_cursor_pb
    from google.cloud.firestore_v1.async_query import AsyncQuery
    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 import document
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import document
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_query import AsyncCollectionGroup
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_client import AsyncClient

    await _stream_helper()


@pytest.mark.asyncio
async def test_asyncquery_stream_w_retry_timeout():

    retry = Retry(predicate=object())
    timeout = 123.0
    await _stream_helper(retry=retry, timeout=timeout)


@pytest.mark.asyncio
async def test_asyncquery_stream_with_limit_to_last():
    # Attach the fake GAPIC to a real client.
    client = _make_client()
    # Make a **real** collection reference as parent.
    parent = client.collection("dee")
    # Execute the query and check the response.
    query = _make_async_query(parent)
    query = query.limit_to_last(2)

    stream_response = query.stream()

    with pytest.raises(ValueError):
        [d async for d in stream_response]


@pytest.mark.asyncio
async def test_asyncquery_stream_with_transaction():
    # Create a minimal fake GAPIC.

    firestore_api = AsyncMock(spec=["run_query"])