Ejemplo n.º 1
0
    def test_export_agent(self):
        # Setup Expected Response
        agent_uri = "agentUri-1700713166"
        expected_response = {"agent_uri": agent_uri}
        expected_response = agent_pb2.ExportAgentResponse(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_export_agent", 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 = dialogflow_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")

        response = client.export_agent(parent)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = agent_pb2.ExportAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 2
0
    def test_export_agent(self):
        # Setup Expected Response
        agent_uri = 'agentUri-1700713166'
        agent_content = b'63'
        expected_response = {
            'agent_uri': agent_uri,
            'agent_content': agent_content
        }
        expected_response = agent_pb2.ExportAgentResponse(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_export_agent', done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.export_agent(parent)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = agent_pb2.ExportAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 3
0
def download_agent(agent_name: str, project_id: str, auth_file: str) -> bytes:
    """
    Downloads an agent from Dialogflow.

    Args:
        agent_name (str): The name of the agent.
        project_id (str): The project id.
        auth_file (str): The name of the authorization file.
    Returns:
        bytes: Returns bytes for the zip file.
    """
    auth = os.path.join(current_directory, "authentication_tokens", auth_file)
    os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = auth

    # Download agent agent_name as bytes.
    client = dialogflow_v2beta1.AgentsClient()
    parent = client.project_path(project_id)
    response = client.export_agent(parent)

    def callback(operation_future):
        result = operation_future.result()

    response.add_done_callback(callback)
    data = response.result().agent_content

    print(data)

    return data
    def test_restore_agent(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = empty_pb2.Empty(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_restore_agent', 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 = dialogflow_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.restore_agent(parent)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = agent_pb2.RestoreAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 5
0
    def test_search_agents(self):
        # Setup Expected Response
        next_page_token = ''
        agents_element = {}
        agents = [agents_element]
        expected_response = {
            'next_page_token': next_page_token,
            'agents': agents
        }
        expected_response = agent_pb2.SearchAgentsResponse(**expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[expected_response])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.search_agents(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.agents[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = agent_pb2.SearchAgentsRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_search_agents(self):
        # Setup Expected Response
        next_page_token = ''
        agents_element = {}
        agents = [agents_element]
        expected_response = {
            'next_page_token': next_page_token,
            'agents': agents
        }
        expected_response = agent_pb2.SearchAgentsResponse(**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_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.search_agents(parent)
        resources = list(paged_list_response)
        assert len(resources) == 1

        assert expected_response.agents[0] == resources[0]

        assert len(channel.requests) == 1
        expected_request = agent_pb2.SearchAgentsRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_validation_result_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.AgentsClient()

        with pytest.raises(CustomException):
            client.get_validation_result()
Ejemplo n.º 8
0
    def test_search_agents_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.search_agents(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Ejemplo n.º 9
0
    def test_get_agent_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup request
        parent = client.project_path('[PROJECT]')

        with pytest.raises(CustomException):
            client.get_agent(parent)
    def test_search_agents_exception(self):
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch('google.api_core.grpc_helpers.create_channel')
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.AgentsClient()

        # Setup request
        parent = client.project_path('[PROJECT]')

        paged_list_response = client.search_agents(parent)
        with pytest.raises(CustomException):
            list(paged_list_response)
Ejemplo n.º 11
0
    def test_delete_agent_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.AgentsClient()

        # Setup request
        parent = client.project_path("[PROJECT]")

        with pytest.raises(CustomException):
            client.delete_agent(parent)
Ejemplo n.º 12
0
    def test_delete_agent(self):
        channel = ChannelStub()
        patch = mock.patch("google.api_core.grpc_helpers.create_channel")
        with patch as create_channel:
            create_channel.return_value = channel
            client = dialogflow_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")

        client.delete_agent(parent)

        assert len(channel.requests) == 1
        expected_request = agent_pb2.DeleteAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 13
0
    def test_restore_agent_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_restore_agent_exception', done=True)
        operation.error.CopyFrom(error)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.restore_agent(parent)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_get_validation_result(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = validation_result_pb2.ValidationResult(
            **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_v2beta1.AgentsClient()

        response = client.get_validation_result()
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = agent_pb2.GetValidationResultRequest()
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_restore_agent_exception(self):
        # Setup Response
        error = status_pb2.Status()
        operation = operations_pb2.Operation(
            name='operations/test_restore_agent_exception', done=True)
        operation.error.CopyFrom(error)

        # 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 = dialogflow_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.restore_agent(parent)
        exception = response.exception()
        assert exception.errors[0] == error
    def test_get_agent(self):
        # Setup Expected Response
        parent_2 = 'parent21175163357'
        display_name = 'displayName1615086568'
        default_language_code = 'defaultLanguageCode856575222'
        time_zone = 'timeZone36848094'
        description = 'description-1724546052'
        avatar_uri = 'avatarUri-402824826'
        enable_logging = False
        classification_threshold = 1.11581064E8
        expected_response = {
            'parent': parent_2,
            'display_name': display_name,
            'default_language_code': default_language_code,
            'time_zone': time_zone,
            'description': description,
            'avatar_uri': avatar_uri,
            'enable_logging': enable_logging,
            'classification_threshold': classification_threshold
        }
        expected_response = agent_pb2.Agent(**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_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.get_agent(parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = agent_pb2.GetAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 17
0
    def test_get_agent(self):
        # Setup Expected Response
        parent_2 = "parent21175163357"
        display_name = "displayName1615086568"
        default_language_code = "defaultLanguageCode856575222"
        time_zone = "timeZone36848094"
        description = "description-1724546052"
        avatar_uri = "avatarUri-402824826"
        enable_logging = False
        classification_threshold = 1.11581064e8
        expected_response = {
            "parent": parent_2,
            "display_name": display_name,
            "default_language_code": default_language_code,
            "time_zone": time_zone,
            "description": description,
            "avatar_uri": avatar_uri,
            "enable_logging": enable_logging,
            "classification_threshold": classification_threshold,
        }
        expected_response = agent_pb2.Agent(**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_v2beta1.AgentsClient()

        # Setup Request
        parent = client.project_path("[PROJECT]")

        response = client.get_agent(parent)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = agent_pb2.GetAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 18
0
    def test_restore_agent(self):
        # Setup Expected Response
        expected_response = {}
        expected_response = empty_pb2.Empty(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_restore_agent', done=True)
        operation.response.Pack(expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[operation])
        client = dialogflow_v2beta1.AgentsClient(channel=channel)

        # Setup Request
        parent = client.project_path('[PROJECT]')

        response = client.restore_agent(parent)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = agent_pb2.RestoreAgentRequest(parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Ejemplo n.º 19
0
def train_agent(project_id):
    import dialogflow_v2beta1
    client = dialogflow_v2beta1.AgentsClient()
    parent = client.project_path(project_id)
    client.train_agent(parent)
Ejemplo n.º 20
0
import dialogflow_v2beta1
client = dialogflow_v2beta1.AgentsClient()
parent = client.project_path('[PROJECT]')
client.delete_agent(parent)
def train_clietn():
    client = dialogflow_v2beta1.AgentsClient()
    parent = client.project_path(os.environ['GOOGLE_PROJECT_NAME'])
    response = client.train_agent(parent)