Exemplo n.º 1
0
    def test_list_time_series(self):
        # Setup Expected Response
        next_page_token = ''
        time_series_element = {}
        time_series = [time_series_element]
        expected_response = {
            'next_page_token': next_page_token,
            'time_series': time_series
        }
        expected_response = metric_service_pb2.ListTimeSeriesResponse(
            **expected_response)

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

        # Setup Request
        name = client.project_path('[PROJECT]')
        filter_ = 'filter-1274492040'
        interval = {}
        view = enums.ListTimeSeriesRequest.TimeSeriesView.FULL

        paged_list_response = client.list_time_series(name, filter_, interval,
                                                      view)
        resources = list(paged_list_response)
        assert len(resources) == 1

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

        assert len(channel.requests) == 1
        expected_request = metric_service_pb2.ListTimeSeriesRequest(
            name=name, filter=filter_, interval=interval, view=view)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request
Exemplo n.º 2
0
    def __init__(self, responses=[]):
        from google.cloud.monitoring_v3.proto import metric_service_pb2

        self.responses = responses
        self.responses = [
            metric_service_pb2.ListTimeSeriesResponse(**response)
            for response in responses
        ]
        self.requests = []
Exemplo n.º 3
0
 def make_grpc_stub(self, nresp=1):
     next_page_token = ""
     time_series_element = self.load_fixture(
         filename=f'{cwd}/fixtures/time_series_proto.json', load_json=True)
     time_series = [time_series_element]
     expected_response = {
         "next_page_token": next_page_token,
         "time_series": time_series,
     }
     expected_response = metric_service_pb2.ListTimeSeriesResponse(
         **expected_response)
     channel = ChannelStub(responses=[expected_response] * nresp)
     return channel
Exemplo n.º 4
0
    def test_list_time_series(self):
        # Setup Expected Response
        next_page_token = ""
        time_series_element = {}
        time_series = [time_series_element]
        expected_response = {
            "next_page_token": next_page_token,
            "time_series": time_series,
        }
        expected_response = metric_service_pb2.ListTimeSeriesResponse(
            **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 = monitoring_v3.MetricServiceClient()

        # Setup Request
        name = client.project_path("[PROJECT]")
        filter_ = "filter-1274492040"
        interval = {}
        view = enums.ListTimeSeriesRequest.TimeSeriesView.FULL

        paged_list_response = client.list_time_series(name, filter_, interval,
                                                      view)
        resources = list(paged_list_response)
        assert len(resources) == 1

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

        assert len(channel.requests) == 1
        expected_request = metric_service_pb2.ListTimeSeriesRequest(
            name=name, filter=filter_, interval=interval, view=view)
        actual_request = channel.requests[0][1]
        assert expected_request == actual_request