def test_it(self): from google.cloud.datastore_v1.proto import datastore_pb2 http = object() project = "projectOK" method = "beginTransaction" base_url = "test.invalid" client_info = _make_client_info() request_pb = datastore_pb2.BeginTransactionRequest(project_id=project) response_pb = datastore_pb2.BeginTransactionResponse(transaction=b"7830rmc") patch = mock.patch( "google.cloud.datastore._http._request", return_value=response_pb.SerializeToString(), ) with patch as mock_request: result = self._call_fut( http, project, method, base_url, client_info, request_pb, datastore_pb2.BeginTransactionResponse, ) self.assertEqual(result, response_pb) mock_request.assert_called_once_with( http, project, method, request_pb.SerializeToString(), base_url, client_info, )
def test_begin_transaction(self): from google.cloud.datastore_v1.proto import datastore_pb2 project = "PROJECT" transaction = b"TRANSACTION" rsp_pb = datastore_pb2.BeginTransactionResponse() rsp_pb.transaction = transaction # 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.begin_transaction(project) # Check the result and verify the callers. self.assertEqual(response, rsp_pb) uri = _build_expected_url(client._base_url, project, "beginTransaction") request = _verify_protobuf_call( http, uri, datastore_pb2.BeginTransactionRequest() ) # The RPC-over-HTTP request does not set the project in the request. self.assertEqual(request.project_id, u"")
def test_begin_transaction(self): # Setup Expected Response transaction = b'-34' expected_response = {'transaction': transaction} expected_response = datastore_pb2.BeginTransactionResponse( **expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = datastore_v1.DatastoreClient(channel=channel) # Setup Request project_id = 'projectId-1969970175' response = client.begin_transaction(project_id) assert expected_response == response assert len(channel.requests) == 1 expected_request = datastore_pb2.BeginTransactionRequest( project_id=project_id) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_it(self): from google.cloud.datastore_v1.proto import datastore_pb2 http = object() project = 'projectOK' method = 'beginTransaction' base_url = 'test.invalid' request_pb = datastore_pb2.BeginTransactionRequest( project_id=project) response_pb = datastore_pb2.BeginTransactionResponse( transaction=b'7830rmc') patch = mock.patch('google.cloud.datastore._http._request', return_value=response_pb.SerializeToString()) with patch as mock_request: result = self._call_fut( http, project, method, base_url, request_pb, datastore_pb2.BeginTransactionResponse) self.assertEqual(result, response_pb) mock_request.assert_called_once_with( http, project, method, request_pb.SerializeToString(), base_url)