def test_get_document(self):
        # Setup Expected Response
        name_2 = "name2-1052831874"
        display_name = "displayName1615086568"
        mime_type = "mimeType-196041627"
        content_uri = "contentUri-388807514"
        enable_auto_reload = False
        expected_response = {
            "name": name_2,
            "display_name": display_name,
            "mime_type": mime_type,
            "content_uri": content_uri,
            "enable_auto_reload": enable_auto_reload,
        }
        expected_response = document_pb2.Document(**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.DocumentsClient()

        # Setup Request
        name = client.document_path("[PROJECT]", "[KNOWLEDGE_BASE]",
                                    "[DOCUMENT]")

        response = client.get_document(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = document_pb2.GetDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_get_document(self):
        # Setup Expected Response
        name_2 = 'name2-1052831874'
        display_name = 'displayName1615086568'
        mime_type = 'mimeType-196041627'
        content_uri = 'contentUri-388807514'
        expected_response = {
            'name': name_2,
            'display_name': display_name,
            'mime_type': mime_type,
            'content_uri': content_uri
        }
        expected_response = document_pb2.Document(**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.DocumentsClient()

        # Setup Request
        name = client.document_path('[PROJECT]', '[KNOWLEDGE_BASE]',
                                    '[DOCUMENT]')

        response = client.get_document(name)
        assert expected_response == response

        assert len(channel.requests) == 1
        expected_request = document_pb2.GetDocumentRequest(name=name)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
示例#3
0
    def test_create_document(self):
        # Setup Expected Response
        name = 'name3373707'
        display_name = 'displayName1615086568'
        mime_type = 'mimeType-196041627'
        content_uri = 'contentUri-388807514'
        expected_response = {
            'name': name,
            'display_name': display_name,
            'mime_type': mime_type,
            'content_uri': content_uri
        }
        expected_response = document_pb2.Document(**expected_response)
        operation = operations_pb2.Operation(
            name='operations/test_create_document', done=True)
        operation.response.Pack(expected_response)

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

        # Setup Request
        parent = client.knowledge_base_path('[PROJECT]', '[KNOWLEDGE_BASE]')
        document = {}

        response = client.create_document(parent, document)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = document_pb2.CreateDocumentRequest(
            parent=parent, document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_create_document(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        mime_type = "mimeType-196041627"
        content_uri = "contentUri-388807514"
        enable_auto_reload = False
        expected_response = {
            "name": name,
            "display_name": display_name,
            "mime_type": mime_type,
            "content_uri": content_uri,
            "enable_auto_reload": enable_auto_reload,
        }
        expected_response = document_pb2.Document(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_create_document", 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.DocumentsClient()

        # Setup Request
        parent = client.knowledge_base_path("[PROJECT]", "[KNOWLEDGE_BASE]")
        document = {}

        response = client.create_document(parent, document)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = document_pb2.CreateDocumentRequest(
            parent=parent, document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
    def test_update_document(self):
        # Setup Expected Response
        name = "name3373707"
        display_name = "displayName1615086568"
        mime_type = "mimeType-196041627"
        content_uri = "contentUri-388807514"
        expected_response = {
            "name": name,
            "display_name": display_name,
            "mime_type": mime_type,
            "content_uri": content_uri,
        }
        expected_response = document_pb2.Document(**expected_response)
        operation = operations_pb2.Operation(
            name="operations/test_update_document", 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.DocumentsClient()

        # Setup Request
        document = {}

        response = client.update_document(document)
        result = response.result()
        assert expected_response == result

        assert len(channel.requests) == 1
        expected_request = document_pb2.UpdateDocumentRequest(
            document=document)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request