async def test__begin_failure(self): from google.cloud.firestore_v1.base_transaction import _CANT_BEGIN client = _make_client() transaction = self._make_one(client) transaction._id = b"not-none" with self.assertRaises(ValueError) as exc_info: await transaction._begin() err_msg = _CANT_BEGIN.format(transaction._id) self.assertEqual(exc_info.exception.args, (err_msg,))
def test_transaction__begin_failure(): from google.cloud.firestore_v1.base_transaction import _CANT_BEGIN client = _make_client() transaction = _make_transaction(client) transaction._id = b"not-none" with pytest.raises(ValueError) as exc_info: transaction._begin() err_msg = _CANT_BEGIN.format(transaction._id) assert exc_info.value.args == (err_msg, )
async def _begin(self, retry_id=None) -> None: """Begin the transaction. Args: retry_id (Optional[bytes]): Transaction ID of a transaction to be retried. Raises: ValueError: If the current transaction has already begun. """ if self.in_progress: msg = _CANT_BEGIN.format(self._id) raise ValueError(msg) transaction_response = await self._client._firestore_api.begin_transaction( request={ "database": self._client._database_string, "options": self._options_protobuf(retry_id), }, metadata=self._client._rpc_metadata, ) self._id = transaction_response.transaction