def test_create_task(self): # Setup Expected Response name = "name3373707" expected_response = {"name": name} expected_response = task_pb2.Task(**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 = tasks_v2beta2.CloudTasksClient() # Setup Request parent = client.queue_path("[PROJECT]", "[LOCATION]", "[QUEUE]") task = {} response = client.create_task(parent, task) assert expected_response == response assert len(channel.requests) == 1 expected_request = cloudtasks_pb2.CreateTaskRequest(parent=parent, task=task) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_task(self): # Setup Expected Response name = 'name3373707' expected_response = {'name': name} expected_response = task_pb2.Task(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = tasks_v2beta2.CloudTasksClient(channel=channel) # Setup Request parent = client.queue_path('[PROJECT]', '[LOCATION]', '[QUEUE]') task = {} response = client.create_task(parent, task) assert expected_response == response assert len(channel.requests) == 1 expected_request = cloudtasks_pb2.CreateTaskRequest( parent=parent, task=task) actual_request = channel.requests[0][1] assert expected_request == actual_request