コード例 #1
0
    def test_list_log_metrics(self):
        # Setup Expected Response
        next_page_token = ""
        metrics_element = {}
        metrics = [metrics_element]
        expected_response = {
            "next_page_token": next_page_token,
            "metrics": metrics
        }
        expected_response = logging_metrics_pb2.ListLogMetricsResponse(
            **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.MetricsServiceV2Client()

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

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

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

        assert len(channel.requests) == 1
        expected_request = logging_metrics_pb2.ListLogMetricsRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #2
0
    def test_list_log_metrics(self):
        # Setup Expected Response
        next_page_token = ''
        metrics_element = {}
        metrics = [metrics_element]
        expected_response = {
            'next_page_token': next_page_token,
            'metrics': metrics
        }
        expected_response = logging_metrics_pb2.ListLogMetricsResponse(
            **expected_response)

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

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

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

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

        assert len(channel.requests) == 1
        expected_request = logging_metrics_pb2.ListLogMetricsRequest(
            parent=parent)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
コード例 #3
0
    def test_list_metrics(self):
        channel, api = self.make_metrics_api()

        sink_msg = logging_metrics_pb2.LogMetric(
            name=self.METRIC_PATH, description=self.DESCRIPTION, filter=FILTER
        )
        channel.ListLogMetrics.response = logging_metrics_pb2.ListLogMetricsResponse(
            metrics=[sink_msg]
        )

        result = api.list_metrics(PROJECT)
        metrics = list(result)

        # Check the response
        assert len(metrics) == 1
        metric = metrics[0]
        assert isinstance(metric, google.cloud.logging.metric.Metric)
        assert metric.name == self.METRIC_PATH
        assert metric.description == self.DESCRIPTION
        assert metric.filter_ == FILTER

        # Check the request
        assert len(channel.ListLogMetrics.requests) == 1
        request = channel.ListLogMetrics.requests[0]
        assert request.parent == PROJECT_PATH
コード例 #4
0
    def test_list_metrics_options(self):
        channel, api = self.make_metrics_api()

        channel.ListLogMetrics.response = logging_metrics_pb2.ListLogMetricsResponse(
            metrics=[]
        )

        result = api.list_metrics(PROJECT, page_size=42, page_token="token")
        list(result)

        # Check the request
        assert len(channel.ListLogMetrics.requests) == 1
        request = channel.ListLogMetrics.requests[0]
        assert request.parent == PROJECT_PATH
        assert request.page_size == 42
        assert request.page_token == "token"