def test_update_intent(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' priority = 1165461084 is_fallback = False ml_disabled = True action = 'action-1422950858' reset_contexts = True root_followup_intent_name = 'rootFollowupIntentName402253784' parent_followup_intent_name = 'parentFollowupIntentName-1131901680' expected_response = { 'name': name, 'display_name': display_name, 'priority': priority, 'is_fallback': is_fallback, 'ml_disabled': ml_disabled, 'action': action, 'reset_contexts': reset_contexts, 'root_followup_intent_name': root_followup_intent_name, 'parent_followup_intent_name': parent_followup_intent_name } expected_response = intent_pb2.Intent(**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 = dialogflow_v2.IntentsClient() # Setup Request intent = {} language_code = 'languageCode-412800396' response = client.update_intent(intent, language_code) assert expected_response == response assert len(channel.requests) == 1 expected_request = intent_pb2.UpdateIntentRequest( intent=intent, language_code=language_code) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_intent(self): # Setup Expected Response name = "name3373707" display_name = "displayName1615086568" priority = 1165461084 is_fallback = False ml_disabled = True action = "action-1422950858" reset_contexts = True root_followup_intent_name = "rootFollowupIntentName402253784" parent_followup_intent_name = "parentFollowupIntentName-1131901680" expected_response = { "name": name, "display_name": display_name, "priority": priority, "is_fallback": is_fallback, "ml_disabled": ml_disabled, "action": action, "reset_contexts": reset_contexts, "root_followup_intent_name": root_followup_intent_name, "parent_followup_intent_name": parent_followup_intent_name, } expected_response = intent_pb2.Intent(**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 = dialogflow_v2.IntentsClient() # Setup Request parent = client.project_agent_path("[PROJECT]") intent = {} response = client.create_intent(parent, intent) assert expected_response == response assert len(channel.requests) == 1 expected_request = intent_pb2.CreateIntentRequest(parent=parent, intent=intent) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_get_intent(self): # Setup Expected Response name_2 = 'name2-1052831874' display_name = 'displayName1615086568' priority = 1165461084 is_fallback = False ml_disabled = True action = 'action-1422950858' reset_contexts = True root_followup_intent_name = 'rootFollowupIntentName402253784' parent_followup_intent_name = 'parentFollowupIntentName-1131901680' expected_response = { 'name': name_2, 'display_name': display_name, 'priority': priority, 'is_fallback': is_fallback, 'ml_disabled': ml_disabled, 'action': action, 'reset_contexts': reset_contexts, 'root_followup_intent_name': root_followup_intent_name, 'parent_followup_intent_name': parent_followup_intent_name } expected_response = intent_pb2.Intent(**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 = dialogflow_v2.IntentsClient() # Setup Request name = client.intent_path('[PROJECT]', '[INTENT]') response = client.get_intent(name) assert expected_response == response assert len(channel.requests) == 1 expected_request = intent_pb2.GetIntentRequest(name=name) actual_request = channel.requests[0][1] assert expected_request == actual_request
def test_create_intent(self): # Setup Expected Response name = 'name3373707' display_name = 'displayName1615086568' priority = 1165461084 is_fallback = False ml_disabled = True action = 'action-1422950858' reset_contexts = True root_followup_intent_name = 'rootFollowupIntentName402253784' parent_followup_intent_name = 'parentFollowupIntentName-1131901680' expected_response = { 'name': name, 'display_name': display_name, 'priority': priority, 'is_fallback': is_fallback, 'ml_disabled': ml_disabled, 'action': action, 'reset_contexts': reset_contexts, 'root_followup_intent_name': root_followup_intent_name, 'parent_followup_intent_name': parent_followup_intent_name } expected_response = intent_pb2.Intent(**expected_response) # Mock the API response channel = ChannelStub(responses=[expected_response]) client = dialogflow_v2.IntentsClient(channel=channel) # Setup Request parent = client.project_agent_path('[PROJECT]') intent = {} response = client.create_intent(parent, intent) assert expected_response == response assert len(channel.requests) == 1 expected_request = intent_pb2.CreateIntentRequest(parent=parent, intent=intent) actual_request = channel.requests[0][1] assert expected_request == actual_request