def test_list_log_entries(self):
        # Setup Expected Response
        next_page_token = ""
        entries_element = {}
        entries = [entries_element]
        expected_response = {
            "next_page_token": next_page_token,
            "entries": entries
        }
        expected_response = logging_pb2.ListLogEntriesResponse(
            **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 = logging_v2.LoggingServiceV2Client()

        # Setup Request
        resource_names = []

        paged_list_response = client.list_log_entries(resource_names)
        resources = list(paged_list_response)
        assert len(resources) == 1

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

        assert len(channel.requests) == 1
        expected_request = logging_pb2.ListLogEntriesRequest(
            resource_names=resource_names)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 2
0
    def test_list_log_entries(self):
        # Setup Expected Response
        next_page_token = ''
        entries_element = {}
        entries = [entries_element]
        expected_response = {
            'next_page_token': next_page_token,
            'entries': entries
        }
        expected_response = logging_pb2.ListLogEntriesResponse(
            **expected_response)

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

        # Setup Request
        resource_names = []

        paged_list_response = client.list_log_entries(resource_names)
        resources = list(paged_list_response)
        assert len(resources) == 1

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

        assert len(channel.requests) == 1
        expected_request = logging_pb2.ListLogEntriesRequest(
            resource_names=resource_names)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Esempio n. 3
0
    def test_list_entries(self):
        channel, api = self.make_logging_api()

        log_entry_msg = log_entry_pb2.LogEntry(
            log_name=self.LOG_PATH, text_payload="text"
        )
        channel.ListLogEntries.response = logging_pb2.ListLogEntriesResponse(
            entries=[log_entry_msg]
        )
        result = api.list_entries([PROJECT], FILTER, google.cloud.logging.DESCENDING)

        entries = list(result)

        # Check the response
        assert len(entries) == 1
        entry = entries[0]
        assert isinstance(entry, google.cloud.logging.entries.TextEntry)
        assert entry.payload == "text"

        # Check the request
        assert len(channel.ListLogEntries.requests) == 1
        request = channel.ListLogEntries.requests[0]
        assert request.project_ids == [PROJECT]
        assert request.filter == FILTER
        assert request.order_by == google.cloud.logging.DESCENDING
Esempio n. 4
0
    def test_list_entries_with_options(self):
        channel, api = self.make_logging_api()

        channel.ListLogEntries.response = logging_pb2.ListLogEntriesResponse(entries=[])

        result = api.list_entries(
            [PROJECT],
            FILTER,
            google.cloud.logging.ASCENDING,
            page_size=42,
            page_token="token",
        )

        list(result)

        # Check the request
        assert len(channel.ListLogEntries.requests) == 1
        request = channel.ListLogEntries.requests[0]
        assert request.project_ids == [PROJECT]
        assert request.filter == FILTER
        assert request.order_by == google.cloud.logging.ASCENDING
        assert request.page_size == 42
        assert request.page_token == "token"