# 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
def test_asynctransaction__clean_up():
    transaction = _make_async_transaction(mock.sentinel.client)
    transaction._write_pbs.extend([mock.sentinel.write_pb1, mock.sentinel.write_pb2])
    transaction._id = b"not-this-time-my-friend"

    ret_val = transaction._clean_up()
    assert ret_val is None

    assert transaction._write_pbs == []
    assert transaction._id is None


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

    # Create a minimal fake GAPIC with a dummy result.
    firestore_api = AsyncMock()
    txn_id = b"to-begin"
    response = firestore.BeginTransactionResponse(transaction=txn_id)
    firestore_api.begin_transaction.return_value = response

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

    # Actually make a transaction and ``begin()`` it.
    transaction = _make_async_transaction(client)
    assert transaction._id is None

    ret_val = await transaction._begin()

# 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

def test_asynctransaction__clean_up():
    transaction = _make_async_transaction(mock.sentinel.client)
    transaction._write_pbs.extend([mock.sentinel.write_pb1, mock.sentinel.write_pb2])
    transaction._id = b"not-this-time-my-friend"

    ret_val = transaction._clean_up()
    assert ret_val is None

    assert transaction._write_pbs == []
    assert transaction._id is None


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

    # Create a minimal fake GAPIC with a dummy result.
    firestore_api = AsyncMock()
    txn_id = b"to-begin"
    response = firestore.BeginTransactionResponse(transaction=txn_id)
    firestore_api.begin_transaction.return_value = response

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

    # Actually make a transaction and ``begin()`` it.
    transaction = _make_async_transaction(client)
    assert transaction._id is None

    ret_val = await transaction._begin()

    assert ret_val is None