def test_rollback_ok(self): from google.cloud.datastore_v1.proto 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_info = _make_client_info() client = mock.Mock( _http=http, _base_url="test.invalid", _client_info=client_info, spec=["_http", "_base_url", "_client_info"], ) # 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): # Setup Expected Response expected_response = {} expected_response = datastore_pb2.RollbackResponse(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = datastore_v1.DatastoreClient(channel=channel) # Setup Request project_id = 'projectId-1969970175' transaction = b'-34' response = client.rollback(project_id, transaction) assert expected_response == response assert len(channel.requests) == 1 expected_request = datastore_pb2.RollbackRequest( project_id=project_id, transaction=transaction) actual_request = channel.requests[0][1] assert expected_request == actual_request