def test_streaming_pull(self):
        # Setup Expected Response
        received_messages_element = {}
        received_messages = [received_messages_element]
        expected_response = {'received_messages': received_messages}
        expected_response = pubsub_pb2.StreamingPullResponse(
            **expected_response)

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

        # Setup Request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        stream_ack_deadline_seconds = 1875467245
        request = {
            'subscription': subscription,
            'stream_ack_deadline_seconds': stream_ack_deadline_seconds
        }
        request = pubsub_pb2.StreamingPullRequest(**request)
        requests = [request]

        response = client.streaming_pull(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
    def test_streaming_pull(self):
        # Setup Expected Response
        received_messages_element = {}
        received_messages = [received_messages_element]
        expected_response = {"received_messages": received_messages}
        expected_response = pubsub_pb2.StreamingPullResponse(
            **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 = subscriber_client.SubscriberClient()

        # Setup Request
        subscription = client.subscription_path("[PROJECT]", "[SUBSCRIPTION]")
        stream_ack_deadline_seconds = 1875467245
        request = {
            "subscription": subscription,
            "stream_ack_deadline_seconds": stream_ack_deadline_seconds,
        }
        request = pubsub_pb2.StreamingPullRequest(**request)
        requests = [request]

        response = client.streaming_pull(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
    def test_streaming_pull_exception(self):
        # Mock the API response
        channel = ChannelStub(responses=[CustomException()])
        client = subscriber_client.SubscriberClient(channel=channel)

        # Setup request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        stream_ack_deadline_seconds = 1875467245
        request = {
            'subscription': subscription,
            'stream_ack_deadline_seconds': stream_ack_deadline_seconds
        }

        request = pubsub_pb2.StreamingPullRequest(**request)
        requests = [request]

        with pytest.raises(CustomException):
            client.streaming_pull(requests)
示例#4
0
    def test_streaming_pull_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 = subscriber_client.SubscriberClient()

        # Setup request
        subscription = client.subscription_path('[PROJECT]', '[SUBSCRIPTION]')
        stream_ack_deadline_seconds = 1875467245
        request = {
            'subscription': subscription,
            'stream_ack_deadline_seconds': stream_ack_deadline_seconds
        }

        request = pubsub_pb2.StreamingPullRequest(**request)
        requests = [request]

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