def test_run_task(self): # Setup Expected Response name_2 = "name2-1052831874" dispatch_count = 1217252086 response_count = 424727441 expected_response = { "name": name_2, "dispatch_count": dispatch_count, "response_count": response_count, } 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_v2beta3.CloudTasksClient() # Setup Request name = client.task_path("[PROJECT]", "[LOCATION]", "[QUEUE]", "[TASK]") response = client.run_task(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = cloudtasks_pb2.RunTaskRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_task(self): # Setup Expected Response name = "name3373707" dispatch_count = 1217252086 response_count = 424727441 expected_response = { "name": name, "dispatch_count": dispatch_count, "response_count": response_count, } 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_v2beta3.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_run_task(self): # Setup Expected Response name_2 = 'name2-1052831874' dispatch_count = 1217252086 response_count = 424727441 expected_response = { 'name': name_2, 'dispatch_count': dispatch_count, 'response_count': response_count } expected_response = task_pb2.Task(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = tasks_v2beta3.CloudTasksClient(channel=channel) # Setup Request name = client.task_path('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]') response = client.run_task(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = cloudtasks_pb2.RunTaskRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_task(self): # Setup Expected Response name_2 = 'name2-1052831874' dispatch_count = 1217252086 response_count = 424727441 expected_response = { 'name': name_2, 'dispatch_count': dispatch_count, 'response_count': response_count } 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_v2beta3.CloudTasksClient() # Setup Request name = client.task_path('[PROJECT]', '[LOCATION]', '[QUEUE]', '[TASK]') response = client.get_task(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = cloudtasks_pb2.GetTaskRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_task(self): # Setup Expected Response name = 'name3373707' dispatch_count = 1217252086 response_count = 424727441 expected_response = { 'name': name, 'dispatch_count': dispatch_count, 'response_count': response_count } expected_response = task_pb2.Task(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = tasks_v2beta3.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