# Path: tests/unit/v1/test__helpers.py
# class AsyncMock(mock.MagicMock):
#     async def __call__(self, *args, **kwargs):
#         return super(AsyncMock, self).__call__(*args, **kwargs)


import mock
import pytest
    import google.auth.credentials
from tests.unit.v1.test__helpers import AsyncMock
    from google.cloud.firestore_v1.async_transaction import AsyncTransaction
    from google.cloud.firestore_v1.async_transaction import MAX_ATTEMPTS
    from google.cloud.firestore_v1.base_transaction import _WRITE_READ_ONLY
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.base_transaction import _CANT_BEGIN
    from google.protobuf import empty_pb2
    from google.cloud.firestore_v1.base_transaction import _CANT_ROLLBACK
    from google.api_core import exceptions
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.cloud.firestore_v1.base_transaction import _CANT_COMMIT
    from google.api_core import exceptions
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_document import AsyncDocumentReference
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_query import AsyncQuery
    from google.cloud.firestore_v1 import _helpers
    from google.cloud.firestore_v1.async_transaction import _AsyncTransactional
    from google.cloud.firestore_v1.types import common
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.cloud.firestore_v1.types import common
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _EXCEED_ATTEMPTS_TEMPLATE
    from google.cloud.firestore_v1.async_transaction import _AsyncTransactional
    from google.cloud.firestore_v1.async_transaction import async_transactional
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.client import Client
    from google.protobuf import empty_pb2
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.cloud.firestore_v1.async_transaction import AsyncTransaction

    ret_val = await transaction._begin()
    assert ret_val is None
    assert transaction._id == txn_id

    # Verify the called mock.
    firestore_api.begin_transaction.assert_called_once_with(
        request={"database": client._database_string, "options": None},
        metadata=client._rpc_metadata,
    )


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

    client = _make_client()
    transaction = _make_async_transaction(client)
    transaction._id = b"not-none"

    with pytest.raises(ValueError) as exc_info:
        await transaction._begin()

    err_msg = _CANT_BEGIN.format(transaction._id)
    assert exc_info.value.args == (err_msg,)


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

    # Create a minimal fake GAPIC with a dummy result.

# 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_async_transaction.py
import mock
import pytest
    import google.auth.credentials
from tests.unit.v1.test__helpers import AsyncMock
    from google.cloud.firestore_v1.async_transaction import AsyncTransaction
    from google.cloud.firestore_v1.async_transaction import MAX_ATTEMPTS
    from google.cloud.firestore_v1.base_transaction import _WRITE_READ_ONLY
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.base_transaction import _CANT_BEGIN
    from google.protobuf import empty_pb2
    from google.cloud.firestore_v1.base_transaction import _CANT_ROLLBACK
    from google.api_core import exceptions
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.cloud.firestore_v1.base_transaction import _CANT_COMMIT
    from google.api_core import exceptions
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_document import AsyncDocumentReference
    from google.cloud.firestore_v1 import _helpers
    from google.api_core.retry import Retry
    from google.cloud.firestore_v1.async_query import AsyncQuery
    from google.cloud.firestore_v1 import _helpers
    from google.cloud.firestore_v1.async_transaction import _AsyncTransactional
    from google.cloud.firestore_v1.types import common
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.api_core import exceptions
    from google.cloud.firestore_v1.types import common
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _EXCEED_ATTEMPTS_TEMPLATE
    from google.cloud.firestore_v1.async_transaction import _AsyncTransactional
    from google.cloud.firestore_v1.async_transaction import async_transactional
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.api_core import exceptions
    from google.cloud.firestore_v1.async_transaction import _commit_with_retry
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.async_transaction import _sleep
    from google.cloud.firestore_v1.client import Client
    from google.protobuf import empty_pb2
    from google.cloud.firestore_v1.types import firestore
    from google.cloud.firestore_v1.types import write
    from google.cloud.firestore_v1.async_transaction import AsyncTransaction


    ret_val = await transaction._begin()
    assert ret_val is None
    assert transaction._id == txn_id

    # Verify the called mock.
    firestore_api.begin_transaction.assert_called_once_with(
        request={"database": client._database_string, "options": None},
        metadata=client._rpc_metadata,
    )


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

    client = _make_client()
    transaction = _make_async_transaction(client)
    transaction._id = b"not-none"

    with pytest.raises(ValueError) as exc_info:
        await transaction._begin()

    err_msg = _CANT_BEGIN.format(transaction._id)
    assert exc_info.value.args == (err_msg,)


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

    # Create a minimal fake GAPIC with a dummy result.

    firestore_api = AsyncMock()