示例#1
0
    def test_rollback_ok(self):
        from google.cloud.proto.datastore.v1 import datastore_pb2

        project = 'PROJECT'
        transaction = b'xact'
        rsp_pb = datastore_pb2.RollbackResponse()

        # Create mock HTTP and client with response.
        http = Http({'status': '200'}, rsp_pb.SerializeToString())
        client = mock.Mock(_http=http, spec=['_http'])

        # Make request.
        conn = self._make_one(client)
        response = conn.rollback(project, transaction)

        # Check the result and verify the callers.
        self.assertEqual(response, rsp_pb)
        uri = '/'.join([
            conn.api_base_url,
            conn.API_VERSION,
            'projects',
            project + ':rollback',
        ])
        cw = http._called_with
        self._verify_protobuf_call(cw, uri, conn)
        request = datastore_pb2.RollbackRequest()
        request.ParseFromString(cw['body'])
        self.assertEqual(request.transaction, transaction)
示例#2
0
    def rollback(self, project_id, transaction, options=None):
        """
        Rolls back a transaction.

        Example:
          >>> from google.cloud.gapic.datastore.v1 import datastore_client
          >>> api = datastore_client.DatastoreClient()
          >>> project_id = ''
          >>> transaction = b''
          >>> response = api.rollback(project_id, transaction)

        Args:
          project_id (string): The ID of the project against which to make the request.
          transaction (bytes): The transaction identifier, returned by a call to
            ``Datastore.BeginTransaction``.
          options (:class:`google.gax.CallOptions`): Overrides the default
            settings for this call, e.g, timeout, retries etc.

        Returns:
          A :class:`google.cloud.proto.datastore.v1.datastore_pb2.RollbackResponse` instance.

        Raises:
          :exc:`google.gax.errors.GaxError` if the RPC is aborted.
          :exc:`ValueError` if the parameters are invalid.
        """
        # Create the request object.
        request = datastore_pb2.RollbackRequest(project_id=project_id,
                                                transaction=transaction)
        return self._rollback(request, options)
示例#3
0
    def test_rollback_ok(self):
        from google.cloud.proto.datastore.v1 import datastore_pb2

        project = 'PROJECT'
        transaction = b'xact'
        rsp_pb = datastore_pb2.RollbackResponse()

        # Create mock HTTP and client with response.
        http = _make_requests_session(
            [_make_response(content=rsp_pb.SerializeToString())])
        client = mock.Mock(_http=http,
                           _base_url='test.invalid',
                           spec=['_http', '_base_url'])

        # Make request.
        ds_api = self._make_one(client)
        response = ds_api.rollback(project, transaction)

        # Check the result and verify the callers.
        self.assertEqual(response, rsp_pb)

        uri = _build_expected_url(client._base_url, project, 'rollback')
        request = _verify_protobuf_call(http, uri,
                                        datastore_pb2.RollbackRequest())
        self.assertEqual(request.transaction, transaction)
    def test_rollback(self, mock_create_stub):
        # Mock gRPC layer
        grpc_stub = mock.Mock()
        mock_create_stub.return_value = grpc_stub

        client = datastore_client.DatastoreClient()

        # Mock request
        project_id = 'projectId-1969970175'
        transaction = b'-34'

        # Mock response
        expected_response = datastore_pb2.RollbackResponse()
        grpc_stub.Rollback.return_value = expected_response

        response = client.rollback(project_id, transaction)
        self.assertEqual(expected_response, response)

        grpc_stub.Rollback.assert_called_once()
        args, kwargs = grpc_stub.Rollback.call_args
        self.assertEqual(len(args), 2)
        self.assertEqual(len(kwargs), 1)
        self.assertIn('metadata', kwargs)
        actual_request = args[0]

        expected_request = datastore_pb2.RollbackRequest(
            project_id=project_id, transaction=transaction)
        self.assertEqual(expected_request, actual_request)
示例#5
0
    def test_rollback_ok(self):
        from google.cloud.proto.datastore.v1 import datastore_pb2

        project = 'PROJECT'
        transaction = b'xact'
        rsp_pb = datastore_pb2.RollbackResponse()

        # Create mock HTTP and client with response.
        http = Http({'status': '200'}, rsp_pb.SerializeToString())
        client = mock.Mock(_http=http,
                           _base_url='test.invalid',
                           spec=['_http', '_base_url'])

        # Make request.
        ds_api = self._make_one(client)
        response = ds_api.rollback(project, transaction)

        # Check the result and verify the callers.
        self.assertEqual(response, rsp_pb)
        uri = _build_expected_url(client._base_url, project, 'rollback')
        cw = http._called_with
        _verify_protobuf_call(self, cw, uri)
        request = datastore_pb2.RollbackRequest()
        request.ParseFromString(cw['body'])
        self.assertEqual(request.transaction, transaction)
示例#6
0
    def rollback(self, project, transaction_id):
        """Rollback the connection's existing transaction.

        Maps the ``DatastoreService.Rollback`` protobuf RPC.

        :type project: str
        :param project: The project to which the transaction belongs.

        :type transaction_id: str
        :param transaction_id: The transaction ID returned from
                               :meth:`begin_transaction`.
        """
        request = _datastore_pb2.RollbackRequest()
        request.transaction = transaction_id
        # Nothing to do with this response, so just execute the method.
        self._datastore_api.rollback(project, request)
示例#7
0
    def rollback(self, project, transaction_id):
        """Rollback the connection's existing transaction.

        Maps the ``DatastoreService.Rollback`` protobuf RPC.

        :type project: str
        :param project: The project to which the transaction belongs.

        :type transaction_id: str
        :param transaction_id: The transaction ID returned from
                               :meth:`begin_transaction`.

        :rtype: :class:`.datastore_pb2.RollbackResponse`
        :returns: The returned protobuf response object.
        """
        request = _datastore_pb2.RollbackRequest()
        request.transaction = transaction_id
        # Response is empty (i.e. no fields) but we return it anyway.
        return self._datastore_api.rollback(project, request)
示例#8
0
    def rollback(self, project, transaction_id):
        """Perform a ``rollback`` request.

        :type project: str
        :param project: The project to connect to. This is
                        usually your project name in the cloud console.

        :type transaction_id: bytes
        :param transaction_id: The transaction ID to rollback.

        :rtype: :class:`.datastore_pb2.RollbackResponse`
        :returns: The returned protobuf response object.
        """
        request_pb = _datastore_pb2.RollbackRequest()
        request_pb.transaction = transaction_id
        # Response is empty (i.e. no fields) but we return it anyway.
        return _rpc(self.client._http, project, 'rollback',
                    self.client._base_url, request_pb,
                    _datastore_pb2.RollbackResponse)