def test_get_model(self): # Setup Expected Response name_2 = "name2-1052831874" display_name = "displayName1615086568" dataset_id = "datasetId-2115646910" etag = "etag3123477" expected_response = { "name": name_2, "display_name": display_name, "dataset_id": dataset_id, "etag": etag, } expected_response = model_pb2.Model(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = automl_v1.AutoMlClient() # Setup Request name = client.model_path("[PROJECT]", "[LOCATION]", "[MODEL]") response = client.get_model(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = service_pb2.GetModelRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_update_model(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" dataset_id = "datasetId-2115646910" etag = "etag3123477" expected_response = { "name": name, "display_name": display_name, "dataset_id": dataset_id, "etag": etag, } expected_response = model_pb2.Model(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = automl_v1.AutoMlClient() # Setup Request model = {} update_mask = {} response = client.update_model(model, update_mask) assert expected_response == response assert len(channel.requests) == 1 expected_request = service_pb2.UpdateModelRequest( model=model, update_mask=update_mask ) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_model(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" dataset_id = "datasetId-2115646910" expected_response = { "name": name, "display_name": display_name, "dataset_id": dataset_id, } expected_response = model_pb2.Model(**expected_response) operation = operations_pb2.Operation( name="operations/test_create_model", done=True ) operation.response.Pack(expected_response) # Mock the API response channel = ChannelStub(responses=[operation]) patch = mock.patch("google.api_core.grpc_helpers.create_channel") with patch as create_channel: create_channel.return_value = channel client = automl_v1.AutoMlClient() # Setup Request parent = client.location_path("[PROJECT]", "[LOCATION]") model = {} response = client.create_model(parent, model) result = response.result() assert expected_response == result assert len(channel.requests) == 1 expected_request = service_pb2.CreateModelRequest(parent=parent, model=model) actual_request = channel.requests[0][1] assert expected_request == actual_request