예제 #1
0
    def test_streaming_detect_intent(self):
        # Setup Expected Response
        response_id = "responseId1847552473"
        output_audio = b"24"
        expected_response = {
            "response_id": response_id,
            "output_audio": output_audio
        }
        expected_response = session_pb2.StreamingDetectIntentResponse(
            **expected_response)

        # Mock the API response
        channel = ChannelStub(responses=[iter([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.SessionsClient()

        # Setup Request
        session = "session1984987798"
        query_input = {}
        request = {"session": session, "query_input": query_input}
        request = session_pb2.StreamingDetectIntentRequest(**request)
        requests = [request]

        response = client.streaming_detect_intent(requests)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        actual_requests = channel.requests[0][1]
        assert len(actual_requests) == 1
        actual_request = list(actual_requests)[0]
        assert request == actual_request
예제 #2
0
    def test_streaming_detect_intent(self):
        # Setup Expected Response
        response_id = 'responseId1847552473'
        output_audio = b'24'
        expected_response = {
            'response_id': response_id,
            'output_audio': output_audio
        }
        expected_response = session_pb2.StreamingDetectIntentResponse(
            **expected_response)

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

        # Setup Request
        session = 'session1984987798'
        query_input = {}
        request = {'session': session, 'query_input': query_input}
        request = session_pb2.StreamingDetectIntentRequest(**request)
        requests = [request]

        response = client.streaming_detect_intent(requests)
        resources = list(response)
        assert len(resources) == 1
        assert expected_response == resources[0]

        assert len(channel.requests) == 1
        actual_requests = channel.requests[0][1]
        assert len(actual_requests) == 1
        actual_request = list(actual_requests)[0]
        assert request == actual_request
예제 #3
0
    def test_streaming_detect_intent_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = dialogflow_v2beta1.SessionsClient(channel=channel)

        # Setup request
        session = 'session1984987798'
        query_input = {}
        request = {'session': session, 'query_input': query_input}

        request = session_pb2.StreamingDetectIntentRequest(**request)
        requests = [request]

        with pytest.raises(CustomException):
            client.streaming_detect_intent(requests)
예제 #4
0
    def test_streaming_detect_intent_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.SessionsClient()

        # Setup request
        session = "session1984987798"
        query_input = {}
        request = {"session": session, "query_input": query_input}

        request = session_pb2.StreamingDetectIntentRequest(**request)
        requests = [request]

        with pytest.raises(CustomException):
            client.streaming_detect_intent(requests)